"spawn id exp5 not open" 使用预期脚本进行 scp 时出错



我有一个期望脚本,它像下面这样开始:

#!/usr/bin/expect -f
set timeout 1200
set prompt {[#$] }
set server [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set package [lindex $argv 3]
spawn scp -o StrictHostKeyChecking=no "$package" ${username}@${server}:~
expect {
timeout { send_user "nscp connect time outn"; exit 1 }
"*assword"
}
after 3000
send "$passwordr"
# wait for upload complete
expect {
timeout { send_user "nscp timeoutn"; exit 1 }
eof
}
....
close

它在 ~15 秒后出现以下消息:

send: spawn id exp5 not open
while executing
"send "$passwordr""

这可能是什么原因呢?exp5 是什么意思? 我也尝试删除"3000 之后"语句,但我收到同样的错误。

当您到达发送密码的位置时,连接已关闭。我怀疑您不需要输入该服务器的密码(设置了ssh密钥?(,并且在3秒过去(after 3000(时,文件传输已完成。

您可以稍微压缩脚本:

#!/usr/bin/expect -f
set timeout 1200
set prompt {[#$] }
lassign $argv server username password package
# if your expect version does not have `lassign`, stick to below
#set server [lindex $argv 0]
#set username [lindex $argv 1]
#set password [lindex $argv 2]
#set package [lindex $argv 3]
spawn scp -o StrictHostKeyChecking=no "$package" ${username}@${server}:~
expect {
timeout    {send_user "nscp time outn"; exit 1}
"*assword" {send "$passwordr"; exp_continue }
eof
}

但是,这失去了连接超时和传输超时之间的区别。

最新更新