我为sftp编写了一个脚本。它工作正常几秒钟。但几秒后退出。我尝试了很多方法,但无法弄清楚问题。这是我的代码。
#!/usr/bin/expect
set now [clock seconds]
set now [expr {$now - 3600}]
set date [clock format $now -format {%Y%m%d%H}]
set SOURCE "/home/sms/SMSC-Sec-2.0.7.0_MT/cdrs/"
spawn sftp root@10.167.250.75
expect "password:"
send "teledna\r"
sleep 1
expect "sftp>"
send "cd /home/sms/CDRS-Noida \r"
expect "sftp>"
send "pwd \r"
expect "sftp>"
send "mput $SOURCE/DNA-AegisGw-CDR_PREPAID_$date*.log \r"
expect -exact "sftp>"
send "quit \r"
send "I am here"
输出:
spawn sftp root@10.167.xx.xx
root@10.167.xx.xx's password:
Connected to 10.167.xx.xx.
sftp> cd /home/sms/CDRS-Noida
sftp> pwd
Remote working directory: /home/sms/CDRS-Noida
sftp> mput /home/sms/SMSC-Sec-2.0.7.0_MT/cdrs//DNA-AegisGw-CDR_PREPAID_2017031618*.log
Uploading /home/sms/SMSC-Sec-2.0.7.0_MT/cdrs//DNA-AegisGw-CDR_PREPAID_201703161800_499_10.170.xx.xx_AS.log to /home/sms/CDRS-Noida/DNA-AegisGw-CDR_PREPAID_201703161800_499_10.170.xx.xx_AS.log
/home/sms/SMSC-Sec-2.0.7.0_MT/cdrs//DNA-AegisGw-CDR_PREPAID_201703161800_499_10.170.xx.xx_AS.log 2% 1088KB 104.3KB/s 06:39 ETA[root@smsc admin]#
几秒钟之后就说出了5个那样的
答案 0 :(得分:2)
由于您{{}}许多文件,预计需要花费很长时间。因此,请尝试在mput
后使用较长的timeout
(默认值:10
):
mput
或者您也可以设置全局send "mput $SOURCE/DNA-AegisGw-CDR_PREPAID_$date*.log \r"
expect -timeout 600 -exact "sftp>"
:
timeout
无限set timeout 600
spawn ...
可以由值timeout
指定。