Reputation: 495
I written a script for 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 [email protected]
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 [email protected]
[email protected]'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
Upvotes: 3
Views: 773
Reputation: 20698
Since you're mput
ing many files it's expected to take quite a while. So try using a longer timeout
(default: 10
) after mput
:
send "mput $SOURCE/DNA-AegisGw-CDR_PREPAID_$date*.log \r"
expect -timeout 600 -exact "sftp>"
or you can also set the global timeout
:
set timeout 600
spawn ...
And an infinite timeout
may be specified with the value −1
.
Upvotes: 4