我有這個期望腳本被另一個腳本調用來記錄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