[英]Expect - Spawn exiting after sometime
I written a script for sftp. 我为sftp编写了一个脚本。 Its working fine for few seconds.
几秒钟的工作正常。 But exiting after few seconds.
但是几秒钟后退出。 I tried in so many ways but cant able to figure out the problem.
我尝试了很多方法,但无法找出问题所在。 Here is my code.
这是我的代码。
#!/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"
Output: 输出:
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]#
Exited after few seconds say 5 like that 几秒钟后退出说5
Since you're mput
ing many files it's expected to take quite a while. 由于您要
mput
许多文件,因此预计将需要一段时间。 So try using a longer timeout
(default: 10
) after mput
: 因此,尝试在
mput
之后使用更长的timeout
(默认值: 10
):
send "mput $SOURCE/DNA-AegisGw-CDR_PREPAID_$date*.log \r"
expect -timeout 600 -exact "sftp>"
or you can also set the global timeout
: 或者您也可以设置全局
timeout
:
set timeout 600
spawn ...
And an infinite timeout
may be designated by the value −1
. 并且无限
timeout
可以由值−1
指定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.