嗨,这是我的期望剧本:
#!/usr/local/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn $env(SHELL)
match_max 100000
send -- "ssh IP_addr\r"
expect -exact "password: "
send -- "something\r"
expect -exact "\r"
#expect -exact "Entering server port, ..... type ^z for port menu."
send -- "\r"
expect -exact "login: "
send -- "admin\r"
expect -exact "password: "
send -- "something\r"
expect -exact "something > "
send -- "reboot\r"
expect -exact "REBOOT THE SYSTEM? (y or n): "
send -- "y\r"
expect -exact "SYSTEM REBOOTING!\r"
set no 20
for {set i 1} {$i < $no} {incr i 1} {
send -- "^[-"
}
expect -exact "\/----Enter Password----\\"
expec eof
我想多次发送转义和连字符,直到收到“/ ----输入密码----- \提示符。但我收到以下错误:
missing close-bracket
while executing
"'send -- "^[-"'
"
("for" body line 2)
invoked from within
"for {set i 1} {$i < $no} {incr i 1} {
'send -- "^[-"'
}"
(file "script_auto.exp" line 31)
我是新手,期待。请告诉我这个错误意味着什么,我该如何解决它。
答案 0 :(得分:5)
expect是Tcl语言的扩展。在Tcl中,方括号用于command substitution,与posix shell中的反引号一样。
更改
send -- "^[-"
到
send -- {^[-}
花括号可以防止命令替换,因此开括号看起来只是一个普通字符。