我写了一个基本的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}
}
}"
谢谢
问题是,[]
在Tcl中有特殊含义。执行命令并返回结果。
更改此:
expect {
"% Invalid*" { send_user "\n Command [ $line ] Failed. \n"; exit 252 }
}
到:
expect {
"% Invalid*" { send_user "\n Command \[ $line \] Failed. \n"; exit 252 }
}
有关更多信息,请参见Tcl手册中的评估与替代3:使用[]将参数分组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句