我是一個新手期望(很多的shell編程雖然)。 我試圖連接到交換機使用期望能夠轉儲它的運行配置。但不知何故我的發送命令似乎沒有發送到交換機。使用SSH和期望連接到交換機
腳本:
#!/usr/bin/expect -f
proc connect {passw} {
expect {
"assword:" {
send "$passw\r"
expect {
"Prompt>" {
return 0
}
}
}
}
# timed out
return 1
}
set user [lindex $argv 0]
set passw [lindex $argv 1]
set host [lindex $argv 2]
#check if all were provided
if { $user == "" || $passw == "" || $host == "" } {
puts "Usage: <user> <passw> <host>\n"
exit 1
}
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no [email protected]$host
set rez [connect $passw]
if { $rez == 0 } {
send {enable\r}
send {show running\r}
exit 0
}
puts "\nError connecting to switch: $host, user: $user!\n"
exit 1
唉,當我運行該腳本(從shell腳本觸發),我可以看到它登錄到交換機上,看到了「提示」,但在此之後腳本似乎已退出,因爲我沒有看到正在執行的'enable'和'show running'命令。
任何人都可以告訴我如何解決這個問題?
Richard。
不是一個答案(因此評論),但你可能想看看如何腐臭(http://www.shrubbery.net/rancid/)做到這一點。 – abligh 2014-10-17 12:24:59