Bash Cisco Expect脚本中出现错误

Bash Cisco Expect脚本中出现错误,bash,tcl,expect,cisco,Bash,Tcl,Expect,Cisco,我写了一个基本的Cisco expect脚本。ssh连接后,我想在从文件发送命令行时检测Cisco错误输出,例如: SPAIN#sow crypto isakmp sa ^ % Invalid input detected at '^' marker. 我想在循环中捕获“%Invalid”,并停止程序 foreach line $data { expect "*#" send "$line\r" expect { "% Invalid*"

我写了一个基本的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 }
}
致:

有关更多信息,请参阅Tcl手册中的

expect {
    "% Invalid*" { send_user "\n Command \[ $line \] Failed. \n"; exit 252 }
}