我有这个期望脚本被另一个脚本调用来记录cisco设备。某些原因变得慢到登录到思科设备。有没有人可以看到任何问题或建议可能会提高此脚本的速度。在此先感谢ssh expect脚本
#!/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"
你是绝对正确的。这里是行暂停,并导致time.send:发送“exit \ r”到{exp6} write()未能写入任何内容 - 将睡眠(1)并重试... 我不知道有什么问题与退出。 – dan 2011-03-15 15:37:28
在您发送退出\ r“'后,您可能需要'expect eof' – 2011-03-15 16:40:08
感谢您的回复.expect eof帮助正确退出,现在是其他一些行有问题 - 期望:读取eof expect:set expect_out(spawn_id )“exp6” expect:set expect_out(buffer)“exit \ r \ n连接到路由器-A关闭。\ r \ r \ n” write()无法写入任何内容 - 将睡眠(1)并重试... write()未能写入任何内容 - 将会进入睡眠状态(1)并重试...我真的不知道什么是写入和失败。 – dan 2011-03-15 18:08:05