Email is not sending when the script is running by CRON

Posted by Adam Blok on Server Fault See other posts from Server Fault or by Adam Blok
Published on 2012-07-06T20:03:08Z Indexed on 2012/07/06 21:18 UTC
Read the original article Hit count: 247

Filed under:
|
|

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 :-/.

#!/bin/sh
filename=$(date +%d-%m-%Y)
backup_dir="/mnt/backup/"
email_from_name="BACKUP"
email_to="my@email"
email_subject="Backup is ready"
email_body_file="/tmp/backup-email-body.txt"

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

© Server Fault or respective owner

Related posts about ubuntu

Related posts about cron