[英]Expect script continues to run even the expect does not match anything
#!/usr/bin/expect
spawn ssh admin@10.10.10.10 -o StrictHostKeyChecking=no
expect "5555:"
send "$password\n"
expect "% "
send "exit\n"
No matter what value wrote on expect "5555:" this command still working and I have ssh connection.无论在expect“5555:”上写什么值,这个命令仍然有效并且我有ssh连接。
You should set a timeout and an action upon the timeout:您应该设置超时和超时时的操作:
#!/usr/bin/expect
set timeout 5
spawn ssh admin@10.10.10.10 -o StrictHostKeyChecking=no
expect {
"5555:" { }
timeout { exit 2 }
}
send "$password\n"
expect "% "
send "exit\n"
Some extra info: the default timeout is 10 seconds.一些额外信息:默认超时为 10 秒。 While expect
ing something, if the pattern has not been seen after $timeout
seconds, the expect
command without a "timeout" pattern simply returns and the script continues.当expect
某事时,如果在$timeout
秒后没有看到该模式,则没有“超时”模式的expect
命令只会返回并且脚本继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.