这是我拥有的代码,我解释了我希望它如何在底部工作。
set 11 "10.0.0.101"
set 12 "10.0.0.12"
set timeout 20
spawn telnet $11
expect {
"Unable to connect to remote host:" {exit}
"login:"
}
send "root\r"
expect "Password:"
send "root\r"
expect "#"
send "shutdown -r now\r"
expect "#"
send "exit\r"
expect "Connection closed by foreign host."
set timeout 20
spawn telnet $12
expect "login:"
send "root\r"
expect "Password:"
send "root\r"
expect "#"
send "shutdown -r now\r"
expect "#"
send "exit\r"
expect "Connection closed by foreign host."
exit
如您所见,我使用它每周使用 crontab 重新启动设备一次,但如果设备没有响应或离线,脚本将在 {exit} 处停止,
所以我想使用 goto 命令或类似命令来运行列表中的下一个 spawn 命令。如果没有 goto 命令,有什么简单的方法可以做到这一点?