corradodev
09-15-2009, 04:12 PM
Filename:sftp_reporting.sh
#!/usr/bin/expect
#get filename
set arg1 [lindex $argv 0]
#timeout in max 100 mins
set timeout 6000
#http://www.linuxquestions.org/questions/linux-general-1/transfer-file-using-expect-and-sftp-626822/
#spawn sftp dcorrado@paypaltech.com
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
#spawn sftp corradod@corradodev.com
#password
expect "password:"
#send "xxxx\n"
#send "xxxxx\n"
send "xxxx\n"
#get file
expect "sftp>"
send "get /ppreports/outgoing/$arg1 \r"
#back to command
expect "sftp>"
send -- "!\r\n"
#search for c* in response and move file
expect -indices -re "c*"
send -- "mv $arg1 /home/corradod/public_html/cart3/scripts/reports/ \r"
#search for c* then exit command
expect -indices -re "c*"
send -- "exit \r"
#exit sftp
expect "sftp>"
send "exit \r"
Filename:test.php
<?php
exec("echo '************************************************* *******' >> sftplog.txt");//put seperator in log file
//exec("./sftpcorradodev.sh >> sftplog.txt");//run script and put in log
exec("./sftp_reporting.sh STL-20090908* >> sftplog.txt");//run script and put in log
//exec("./scp_reporting.sh STL-20090908* >> sftplog.txt");//run script and put in log
exec("echo '************************************************* *******' >> sftplog.txt");//put seperator in log file
?>
So I have been working on this a while and I am getting there. It seems my issue is with running a php script using exec calling a shell script in cron.
It works if I run the shell script by it self.
./sftp_reporting.sh STL-20090908*
./sftp_reporting.sh STL-20090908*
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
sftp> get /ppreports/outgoing/STL-20090908*
Fetching /ppreports/outgoing/STL-20090908.01.001.CSV to STL-20090908.01.001.CSV
/ppreports/outgoing/STL-20090908.01.001.CSV 100% 1130 1.1KB/s 00:00
sftp> !
mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
exit
corradod@corradodev.com [~/public_html/cart3/scripts]#
corradod@corradodev.com [~/public_html/cart3/scripts]# mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
corradod@corradodev.com [~/public_html/cart3/scripts]# exit
exit
sftp>
It works if I run the php script that runs the shell script in ssh.
php test.php
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
sftp> get /ppreports/outgoing/STL-20090908*
Fetching /ppreports/outgoing/STL-20090908.01.001.CSV to STL-20090908.01.001.CSV
/ppreports/outgoing/STL-20090908.01.001.CSV 0% 0 0.0KB/s --:-- ETA/ppreports/outgoing/STL-20090908.01.001.CSV 100% 1130 1.1KB/s 00:00
sftp> !
mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
exit
corradod@corradodev.com [~/public_html/cart3/scripts]#
corradod@corradodev.com [~/public_html/cart3/scripts]# mv STL-20090908* /home/co rradod/public_html/cart3/scripts/reports/
corradod@corradodev.com [~/public_html/cart3/scripts]# exit
exit
sftp>
Cron Job Simple in HostMonster works when I use the shell script
exec /home/corradod/public_html/cart3/scripts/sftp_reporting.sh STL-20090908*
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
sftp> get /ppreports/outgoing/STL-20090908*
Fetching /ppreports/outgoing/STL-20090908.01.001.CSV to STL-20090908.01.001.CSV
/ppreports/outgoing/STL-20090908.01.001.CSV 0% 0 0.0KB/s --:-- ETA
/ppreports/outgoing/STL-20090908.01.001.CSV 100% 1130 1.1KB/s 00:00
sftp> !
mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
exit
sh-3.2$
sh-3.2$ mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
sh-3.2$ exit
exit
sftp>
cron doesnt work when I use php and exec call to shell script
************************************************** ******
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
As you can see it just timesout in the middle of the exec. I tried with different sftp servers and it still gives the same result. But if I use my hostmonster and try to sftp into that it works fine. So that leads me to believe its related to a timeout in the exec.
I just cant figure it out. I tried a whole bunch of things. Such as adding php.ini max_input_time. I also tried adding set_time_limit
Anyone have any further input. I would appreciate it whatever you have. It would be awesome if someone could try this on their hostmonster account and see what server settings I need to adjust or whatever. I appreciate any help. Thanks.
#!/usr/bin/expect
#get filename
set arg1 [lindex $argv 0]
#timeout in max 100 mins
set timeout 6000
#http://www.linuxquestions.org/questions/linux-general-1/transfer-file-using-expect-and-sftp-626822/
#spawn sftp dcorrado@paypaltech.com
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
#spawn sftp corradod@corradodev.com
#password
expect "password:"
#send "xxxx\n"
#send "xxxxx\n"
send "xxxx\n"
#get file
expect "sftp>"
send "get /ppreports/outgoing/$arg1 \r"
#back to command
expect "sftp>"
send -- "!\r\n"
#search for c* in response and move file
expect -indices -re "c*"
send -- "mv $arg1 /home/corradod/public_html/cart3/scripts/reports/ \r"
#search for c* then exit command
expect -indices -re "c*"
send -- "exit \r"
#exit sftp
expect "sftp>"
send "exit \r"
Filename:test.php
<?php
exec("echo '************************************************* *******' >> sftplog.txt");//put seperator in log file
//exec("./sftpcorradodev.sh >> sftplog.txt");//run script and put in log
exec("./sftp_reporting.sh STL-20090908* >> sftplog.txt");//run script and put in log
//exec("./scp_reporting.sh STL-20090908* >> sftplog.txt");//run script and put in log
exec("echo '************************************************* *******' >> sftplog.txt");//put seperator in log file
?>
So I have been working on this a while and I am getting there. It seems my issue is with running a php script using exec calling a shell script in cron.
It works if I run the shell script by it self.
./sftp_reporting.sh STL-20090908*
./sftp_reporting.sh STL-20090908*
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
sftp> get /ppreports/outgoing/STL-20090908*
Fetching /ppreports/outgoing/STL-20090908.01.001.CSV to STL-20090908.01.001.CSV
/ppreports/outgoing/STL-20090908.01.001.CSV 100% 1130 1.1KB/s 00:00
sftp> !
mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
exit
corradod@corradodev.com [~/public_html/cart3/scripts]#
corradod@corradodev.com [~/public_html/cart3/scripts]# mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
corradod@corradodev.com [~/public_html/cart3/scripts]# exit
exit
sftp>
It works if I run the php script that runs the shell script in ssh.
php test.php
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
sftp> get /ppreports/outgoing/STL-20090908*
Fetching /ppreports/outgoing/STL-20090908.01.001.CSV to STL-20090908.01.001.CSV
/ppreports/outgoing/STL-20090908.01.001.CSV 0% 0 0.0KB/s --:-- ETA/ppreports/outgoing/STL-20090908.01.001.CSV 100% 1130 1.1KB/s 00:00
sftp> !
mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
exit
corradod@corradodev.com [~/public_html/cart3/scripts]#
corradod@corradodev.com [~/public_html/cart3/scripts]# mv STL-20090908* /home/co rradod/public_html/cart3/scripts/reports/
corradod@corradodev.com [~/public_html/cart3/scripts]# exit
exit
sftp>
Cron Job Simple in HostMonster works when I use the shell script
exec /home/corradod/public_html/cart3/scripts/sftp_reporting.sh STL-20090908*
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
sftp> get /ppreports/outgoing/STL-20090908*
Fetching /ppreports/outgoing/STL-20090908.01.001.CSV to STL-20090908.01.001.CSV
/ppreports/outgoing/STL-20090908.01.001.CSV 0% 0 0.0KB/s --:-- ETA
/ppreports/outgoing/STL-20090908.01.001.CSV 100% 1130 1.1KB/s 00:00
sftp> !
mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
exit
sh-3.2$
sh-3.2$ mv STL-20090908* /home/corradod/public_html/cart3/scripts/reports/
sh-3.2$ exit
exit
sftp>
cron doesnt work when I use php and exec call to shell script
************************************************** ******
spawn sftp sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com
Connecting to reports.sandbox.paypal.com...
sftphO_dcorradocartpaypal.com@reports.sandbox.payp al.com's password:
As you can see it just timesout in the middle of the exec. I tried with different sftp servers and it still gives the same result. But if I use my hostmonster and try to sftp into that it works fine. So that leads me to believe its related to a timeout in the exec.
I just cant figure it out. I tried a whole bunch of things. Such as adding php.ini max_input_time. I also tried adding set_time_limit
Anyone have any further input. I would appreciate it whatever you have. It would be awesome if someone could try this on their hostmonster account and see what server settings I need to adjust or whatever. I appreciate any help. Thanks.