2

We have an rsync script for making a backup from server 1 to server 2. The server is Centos-type, Amazon Linux AMI. The script is executed daily via crontab. The backup is made, so cron runs and the script works. A log is created and should be sent to us via mail. This doesn't happen for some reason. If I run the script manually, the mail is sent, so the mailserver (Postfix) works, and the mail script at the end of the rsync script works as well. Below you see the rsync script:

echo "To: john@testdomain.info" > /tmp/rsync_test.log
echo "From: server@testdomain.info" >> /tmp/rsync_test.log
echo "Subject: Testmail >> /tmp/rsync_test.log
echo "" >> /tmp/rsync_test.log
cat /tmp/rsync_test.log | sendmail -t

Why doesn't this work and how can I fix it?

  • Does the file /tmp/rsync_test.log exist? Is the sendmail binary located in $PATH? – Ansgar Esztermann Feb 23 '15 at 11:42
  • The file still exists. Using locate sendmail I find /usr/lib/sendmail,/usr/lib/sendmail.postfix,/usr/sbin/sendmail,/usr/sbin/sendmail.postfix. $PATH: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin, so that should work. I can execute sendmail from the commandline. And remember that the script works when executed manually. – SPRBRN Feb 23 '15 at 11:53
4

Cron tasks run in limited environment Paricularly, PATH env variable may not contain path to cat or sendmail

Try to specify the fullpath:

/bin/cat /tmp/rsync_test.log | /usr/sbin/sendmail -t

That's my guess.

If you wan to know exact reason, capture stdout and stderr of your crontask script into a log file when setting your cronatsk

*/5 * * * * /your/scripts/task.sh >/somepath/file.log 2>&1

there it'll tell you the error message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.