I have (from one tutorial) cron job which make weekly backup on my website and is working fine.

NOW=$(date +"%Y-%m-%d-%H%M")



tar -cvf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR

tar --append --file=$BACKUP_DIR/$FILE --transform $DB_TRANSFORM $BACKUP_DIR/$DB_FILE

Question is, can someone help me how can I made when backup is done to send me email?

I'm using bash for first time and I'm not sure what I doing.


Edit your crontab file and add:


and at the end of the script add:

echo 'backup finished', $FILE

cron normally sends any output from the command it runs per email. Your script seems to be running silently, hence no email.

If you don't add the MAILTO, the mail will go to the user running the crontab, IMHO it is better to make that explicit.

  • I added those 2 lines at the end of my script but didn't receive email. – Jason Paddle Jun 26 '13 at 12:39
  • Have you set your MAILTO in the crontab correctly and have you tested by hand that the webite's server actually can send email ( ` echo 'test' | mail your@email.adr`)? – Anthon Jun 26 '13 at 12:41
  • Actually was my mistake. I forgot to set my email in crontab. After I set proper emial now is received. But any chance to customize a little text body in email because now is 500+ rows?... I just want to write "Backup for website-date is done". – Jason Paddle Jun 26 '13 at 12:50
  • Don't use the verbose flag (tar -v), or else redirect the stdout from your commands. Then you'll be left with simply what you put to stdout specifically, e.g. "Backup done" – dougBTV Jun 26 '13 at 12:56
  • U mean here tar -cvf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR to use only tar -cf...? – Jason Paddle Jun 26 '13 at 12:58

You can add the following line at the end of your bash script:

echo -e "Sending Backup report :\n Backup of $DB_NAME and $FILE completed " | mutt -s "Backup report for $NOW"

  • This is working also fine. Thank for your help too. I don't have 15 reputation to vote up. Sorry. – Jason Paddle Jun 26 '13 at 13:03
  • Now, you do :-) – Afr Jun 30 '13 at 20:20

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.