Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 finally set up a realistic backup schedule on my data through a shell script, which are handled by cron on tight intervals. Unfortunately, I keep getting empty emails each time the CRON has been executed and not only when things go wrong.

Is it possible to only make CRON send emails when something goes wrong, ie. my TAR doesn't execute as intended?

Here's how my crontab is setup for the moment;

0 */2 * * * /bin/ 2>&1 | mail -s "Backup status"

Thanks a lot!

share|improve this question
up vote 29 down vote accepted

Ideally you'd want your backup script to output nothing if everything goes as expected and only produce output when something goes wrong. Then use the MAILTO environment variable to send any output generated by your script to your email address.
0 */2 * * * /bin/

If your script normally produces output but you don't care about it in cron, just sent it to /dev/null and it'll email you only when something is written to stderr.
0 */2 * * * /bin/ > /dev/null
share|improve this answer

Cronic ( looks like a good idea; to use it you don't have to change your scripts.

share|improve this answer
I really don't see how that will help when the problem is nothing more than an incorrect cron line and cron is doing exactly what it is told to do. – John Gardeniers Feb 14 '12 at 0:17
@JohnGardeniers it helps because sometimes you have output without an error. – Mikhail Aug 31 '14 at 19:59
Alternatively, chronic from the moreutils package: – Vladimir Panteleev May 29 '15 at 22:05

You are specifically instructing cron to always send email, even when /bin/ (don't put it there btw) succeeds. Just omit the | mail -s "Backup status" part and email will only be sent when there is output. You can probably (depending on your cron) explicitly set the email address to mail to as an assignment in the crontab file.

For details, see

man 5 crontab
share|improve this answer

You should be directing the stderr anmd not both stdout and stderr.

Use 1> /dev/null not 2>&1 and it should be fine. Also, you may need to report the error correctly in your backup script.

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.