Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote the simple backup bash script and at the end of it, it's sending an email to me that backup is ready. Everything works perfect when I run this script from terminal (root), but when the script is running by CRON, email is not sending :-/.

filename=$(date +%d-%m-%Y)
email_subject="Backup is ready"

tar czf "$backup_dir$filename.tgz" "/home/www"

echo "Subject: $email_subject" > $email_body_file
ls $backup_dir -sh >> $email_body_file

sendmail -F $email_from_name  -t $email_to < $email_body_file
share|improve this question
-t means extract recipients from message headers. -F sets the fullname of the sender and -f sets the envelope sender address. – adamo Jul 6 '12 at 20:54

Cronjobs run in a minimal environment, so you can't even assume that $PATH is set correctly. The script is probably failing to find the sendmail executable. Set $PATH explicitly in the crontab to something like this, or specify the full path to sendmail in the script.

share|improve this answer
and after setting path add export PATH in the very next line – adamo Jul 6 '12 at 20:45
@adamo Not in crontabs. – mgorven Jul 6 '12 at 20:49
Yep! I missed that part. Diagonally I assumed that you meant that he should set PATH in his script. – adamo Jul 6 '12 at 20:51
Yea! You're right! I changed "sendmail" to "/usr/sbin/sendmail" and it works perfect now! Thanks – Adam Jul 7 '12 at 13:05
You should accept this as the answer:… – MECU Jan 8 '13 at 19:27

This is the environment issue , we need to set the env path in cron as below

38 03 * * 5  /bin/ksh c ". /home/adcis/caliber/.profile ;
/home/xyz/abc/ABCD_BATCH/REPORT_ABC/amb_main_script.ksh" >> /home/xyz/abc/ABCD_BATCH/LOGS/output.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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