下面是我生成的期望脚本,但是当主机不可访问时,它将在屏幕上显示错误,如下所示。我试图让脚本不显示输出错误,并继续循环中的下一个主机
这是期望脚本
#!/usr/bin/expect -f
#Argument passed from 1st script to here, and loops with expect script
set HOST [lindex $argv 0]
foreach host $HOST {
set timeout 10
global spawn_id
spawn ssh $HOST
expect {
"Password:" {send "password\r"}
"*No route to host"
{puts "Host error -> $expect_out(buffer)";exit}
"ssh_exchange_identification: Connection closed by
remote host"
{puts "Host error -> $expect_out(buffer)";exp_continue}
}
expect "*~ $"
#Log into Switch
send "ssh user@x.x.x.x\r"
expect "RSA key fingerprint" {send "yes\r"; exp_continue}
expect "Password:"
send "password\r"
expect eof
}
这是主机不可访问时显示的输出
send: spawn id exp4 not open
while executing
"send "ssh user@x.x.x.x\r""
("foreach" body line 12)
invoked from within
"foreach host $HOST {
set timeout 10
global spawn_id
log_user 0
spawn ssh $HOST
expect "Password:"
send "password\r"..."
(file "/path/to/file/expect_script.sh" line 6)
任何帮助将不胜感激。