Ssh expect script?

Add exp_internal 1 to your expect script. You'll be able to see how expect is matching the patterns. I suspect that your script happens to be pausing for $timeout seconds because one of your patterns failed to match.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I have this expect script which called by another script to log cisco devices. Some reason become become slow to log to cisco devices. Is there any one can see any problem or suggestion may increase the speed for this script.

Thanks in advance #! /usr/bin/expect log_user 0 set timeout 10 set userid "id" set password "pass" # ############## Get two arguments - (1) Device (2) Command to be executed set device lindex $argv 0 set command lindex $argv 1 spawn /usr/bin/ssh -l $userid $device match_max expr 32 * 1024 expect { -re "RSA key fingerprint" {send "yes\r"} timeout {puts "Host is known"} } expect { -re "username: " {send "$userid\r"} -re "(P|p)assword: " {send "$password\r"} -re "Warning:" {send "$password\r"} -re "Connection refused" {puts "Host error -> $expect_out(buffer)";exit} -re "Connection closed" {puts "Host error -> $expect_out(buffer)";exit} -re "no address. *" {puts "Host error -> $expect_out(buffer)";exit} timeout {puts "Timeout error.

Is device down or unreachable? Ssh_expect";exit} } expect { -re "\#>$" {send "term len 0\r"} timeout {puts "Error reading prompt -> $expect_out(buffer)";exit} } expect { -re "\#>$" {send "$command\r"} timeout {puts "Error reading prompt -> $expect_out(buffer)";exit} } expect -re "\#>$" set output $expect_out(buffer) send "exit\r" puts "$output\r\n" ssh expect link|improve this question edited Mar 15 '11 at 1:52John Zwinck14.8k1739 asked Mar 15 '11 at 1:37dan605 80% accept rate.

You are absolutely right. Here is the line pause and cause time out. Send: sending "exit\r" to { exp6 } write() failed to write anything - will sleep(1) and retry... I don't know what's the problem with exit.

– dan Mar 15 '11 at 15:37 after you send "exit\r" you might want to expect eof – glenn jackman Mar 15 '11 at 16:40 thanks for your response. Expect eof help to exit properly now is some other line has issue - expect: read eof expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "exit\r\nConnection to router-A closed. \r\r\n" write() failed to write anything - will sleep(1) and retry... write() failed to write anything - will sleep(1) and retry... I really don't know what's try to write and failed.

– dan Mar 15 '11 at 18:08.

This might be better asked on ServerFault. Anyway, I'd first make sure the servers or devices hosting the ssh daemon are not running low on entropy, and I'd use Wireshark or similar to analyze the traffic to see which side of the connection seems to be waiting for the other.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions