我試圖讓我的期望腳本讀取文件,爲文件的每一行運行命令並退出保存日誌。代碼如下:[期待] spawn id exp7未打開
#!/usr/bin/expect -f
set user [lrange $argv 0 0]
set password [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set arg1 [lrange $argv 3 3]
set systemTime [clock seconds]
set time [clock format $systemTime -format %a_%b_%d_%[email protected]%H'%M'%S]
set fp [open "$arg1" r]
set a "ssh-"
set b ".txt"
set s "_"
append newfile "${a}${arg1}${s}${time}${b}"
set timeout -1
spawn ssh [email protected]$ipaddr
match_max 100000
expect "*?assword:*"
send -- "$password\r"
log_file "$newfile" ;
expect "*#"
send_user "This is the $argv0 Script\r"
while {[gets $fp line] != -1} {
send -- "scm $line\r"
expect "*#"
}
close
send -- "exit\r"
expect eof
我的問題是,一旦涉及到文件我得到以下錯誤的末尾:
E6000_Lab_1# send: spawn id exp7 not open
while executing
"send -- "exit\r""
(file "filetest.tcl" line 28)
誰能幫助我擺脫這種錯誤的嗎?