I have the following entry running and I receive an email..

* * * * * echo "blaah"

However, when I have this as a cron job, no email is received...

* * * * * sh /scripts/mysql-backup-bak.sh >> /var/log/mysql-backup.log 2>&1

...although the script runs and sends to the log file just fine. What I'm ultimately trying to do is have it send an email for any errors. But at this point, I can't get it to send at anytime. Is this possible?

1 Answer 1


The second command doesn't produce any output because all output is redirected to the log file. So there is no output to mail. If you want a mail on errors, create output in case of error.

Like this

* * * * * sh /scripts/mysql-backup-bak.sh >> /var/log/mysql-backup.log 2>&1 || echo "something went wrong"
  • Sorry, that was a typo when I copy/pasted. I've fixed my post.
    – Jay
    Aug 11, 2018 at 22:30
  • ...but I tried it both with quotes and without, it made no difference.
    – Jay
    Aug 11, 2018 at 22:32
  • I changed the answer.
    – RalfFriedl
    Aug 11, 2018 at 22:34
  • Ok, I've modified my statement to look like yours and added a random character to my script to generate an error. No email received. Although, the output doesn't explicitly say "error" when the cron job is running - is that a requirement for cron to assume there's an error? I'm not sure how it decides when there is or isn't an error running the job.
    – Jay
    Aug 11, 2018 at 22:42
  • If I take your line and swap the two statements like this... * * * * * echo "something went wrong" || sh /scripts/mysql-backup-bak.sh >> /var/log/mysql-backup.log 2>&1, it will both send an email and write to the logs. Now I'm just not sure how to get to send an email on errors.
    – Jay
    Aug 11, 2018 at 22:49

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.