简体   繁体   English

如果远程交换机在期望脚本中没有响应,如何继续下一个命令

[英]How to continue with next command if the remote switch is not responding in an expect script

I'm passing the switch name from a bash script. 我正在从bash脚本传递开关名称。 The bash script iterates through a text file and sends the switch name. bash脚本遍历文本文件并发送开关名称。 Sometimes if the switch is not responding, the expect script gets stuck. 有时,如果开关没有响应,则expect脚本会卡住。 I want the script to wait for some time and move to next switch or at least come out. 我希望脚本等待一段时间,然后转到下一个开关,或者至少出来。 I have used the timeout but with no help. 我已经使用了超时,但是没有帮助。

set timeout 60
.
.
.
expect "*> "
send "ssh -l admin $switchName.XXX.XXXXXX.net switchshow -portname > $filename1\r"
sleep 2
expect {
        "*(yes/no)? " {
                send "yes\r"
                exp_continue
        }

        "*assword: " {
                send "$password\r"
        }
        default {
                exp_continue
        }
}

Any suggestion is appreciated. 任何建议表示赞赏。

you want to expect to see the "timeout" keyword: 您希望看到“超时”关键字:

expect {
        timeout {
                puts "timed out waiting for $switchName"
        }
        "*(yes/no)? " {
                send "yes\r"
                exp_continue
        }

        "*assword: " {
                send "$password\r"
                exp_continue
        }
        eof
} 

I also updated your conditions a bit so that you remain in the expect "loop" until the ssh command completes. 我还对您的条件进行了一些更新,以使您保持期望的“循环”状态,直到ssh命令完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM