【发布时间】:2014-10-06 08:12:01
【问题描述】:
我有一个登录到设备列表并运行一系列命令的期望脚本。 一切正常,除非其中一台主机无法访问并且脚本刚刚退出。有没有办法让它跳过无法访问的主机并转移到剩余的设备上?
这是我脚本的主体。
foreach host $hosts {
spawn -noecho /usr/bin/ssh user@$host
set timeout 10
expect {
"assword:" { send [string trimright "$pwd" "\r"] }
"No route*" {puts "Host error -> $expect_out(buffer)";exit}
"Could not resolve*" {puts "Host error -> $expect_out(buffer)";exit}
}
expect "#"
send "term len 0\r"
expect "#"
send "show version\r"
expect "#"
send "exit\r"
expect eof
}
这就是我得到的:
.
. <output of reachable device - R1>
.
Connection to R1 closed by remote host.
Connection to R1 closed.
ssh: Could not resolve hostname R2: Name or service not known
Host error -> ssh: Could not resolve hostname R1: Name or service not known
【问题讨论】:
标签: loops scripting automation tcl expect