【发布时间】:2016-07-09 08:46:52
【问题描述】:
我编写了一个基本的 Cisco expect 脚本。 ssh 连接后,我想在从文件发送命令行时检测 Cisco 错误输出,例如:
SPAIN#sow crypto isakmp sa
^
% Invalid input detected at '^' marker.
我想在我的循环中捕获“% Invalid”并停止程序。
foreach line $data {
expect "*#"
send "$line\r"
expect {
"% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252 }
}
我在输出中得到这些错误:
SPAIN>enable
Password:
SPAIN#sow crypto isakmp sa
^
% Invalid input detected at '^' marker.
SPAIN#invalid command name "sow crypto isakmp sa"
while executing
"$line "
invoked from within
"expect {
"% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252}
}"
("foreach" body line 4)
invoked from within
"foreach line $data {
expect "*#"
send "$line\r"
expect {
"% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252}
}
}"
谢谢
【问题讨论】: