I have a script
a.sh, which has an
echo "Starting to sftp..." sftp email@example.com << END_SCRIPT ls mput *.csv.gz bye END_SCRIPT echo "Sftp successfully."
If I run it interactively, the log output from
sftp is shown. However, if I set it in a crontab and redirect the stdout to a file using
>, there will be only the output from the two
echo statements. How can I get the log from the
I tried the following forms and it didn't work too.
sftp -b batch_file.txt firstname.lastname@example.org ( redirect from cron )
sftp -b batch_file.txt email@example.com >> some_file.log ( redirect from cron + redirect from this line )
I think the problem should be related to the nature of sftp that it is supposed to be run interactively, as stated in the man page. But I cannot find the solution.
My distribution :
Red Hat Enterprise Linux AS release 3 (Taroon Update 2)
the crontab entry:
52 14 * * * sh /home/xxx/testing/xxx.sh > /home/xxx/testing/xxx_`date +\%Y\%m\%d`.log
And the log is created with a time matching the crontab entry.
OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f
I found that if I redirect the output of sftp in the script file to an text file, the message from sftp is logged. Then I remove the log file and scheduled it with cron. After the cron execution, the log file is generated but have no message from sftp. Instead, it only contain log from other statement inside the script file.
If I redirect the output of sftp in script file and run it interactively, the log are perfectly fine. However if I scheduled it with cron ( no redirect in the crontab entry, just simply schedule it ), the log from sftp is gone too.