expect set time out问题

通过expect scp远端文件时,如果遇到远端连接不上的情况,如何缩短scp等待的时间?

哪个大神知道请指导一下,万分感谢🙏

我自己写的expect脚本如下所示,虽然在开头设置了set timeout 5,但是在测试的时候发生,如果远端的网络连接不上,需要等待20s左右才会退出scp,无法实现5s就让scp退出结束

#!/bin/bash

##
# scp Remote Log to local
##
expectResponseCMD="
    expect {
        \"*yes/no\" {set timeout 3; send \"yes\r\"; exp_continue }
        \"*assword:\" {set timeout 3; send \"a1234\r\" }        
}
"

/usr/bin/expect << EOF
set timeout 5
spawn scp -r ${remoteUserName}@${remoteIPAddress}:${remoteFileStoreDirectory}${sn}  ${localFileStoreDirectory}
${expectResponseCMD}
set timeout 10
expect ${remoteEndFlag} { send "exit\r"}
EOF

控制台的执行

% ./expectGrammarTest.sh  
spawn scp -r patrickqiwei@192.100.23.219:~/Library/Logs/DataCollection/testFile /Users/patrick/Library/Logs/DataCollectionBackup/
(这一步scp花费20s才结束退出)
% 
阅读 1.3k
1 个回答
✓ 已被采纳新手上路,请多包涵

找了一下这个问题可以使用scp本身的timeout参数来解决,使用scp -o "ConnectTimeout 10",完整命令如下:

scp -o "ConnectTimeout 5" -r /Users/patrick/Desktop/101-GitRunner patrick@10.190.0.1:~/Desktop
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进