我正在写一个期望脚本telnet到路由器,做一些配置,期待一些输出。
如果没有所需的提示,则等待它并获得超时。 那么我该如何处理这个并打印错误消息。
set timeout 30;
puts "Telnet to $IP 2361\n\n";
spawn telnet $IP 2361;
expect ">";
send "ACT-USER::$user_name:1::$password;";
expect ">";
如果未收到预期值,我如何处理和打印错误消息?
答案 0 :(得分:3)
处理超时很好地需要稍微复杂一点expect
:
expect {
">" {
# Got it; don't need to do anything here because we run the code after
}
timeout {
send_user "timed out, oh no!\n"
exit 1
}
}
# Now we put the rest of the script...
send "ACT-USER....blah"
# ...
请注意,我很惊讶您的send
未以\r
结尾(模拟按返回键)。