Screw your contrast

March 09, 2004

Suppressing Crontab Emails

So, you’ve set up your email reminders and your MP3 alarm clock, but now you’re getting all this mail from crontab. Like you needed a reminder from the computer that it did what you told it to do. Why is it doing this? How do you fix it?

Whenever cron executes one of the entries listed in a users crontab file, it takes the standard output or standard error (or both) and mails them to the owner of the crontab file. Why? That output doesn’t get sent to the console and it isn’t logged either, so it has to go somewhere. However, you can specify where you want the output sent. Here’s how to suppress crontab emails.

There are a couple of ways you can remedy this behaviour:

  1. At the top of the crontab file, place the following command:
    MAILTO=”" (That’s a null or just two quotes back to back)
  2. Redirect the output of the offending program in your crontab
    20 6 * * 1-5 /home/grim/alarm >& /dev/null
Method #1 will suppress ALL email from your crontab. It does this by telling cron to mail your output to nobody. It will simply vanish from your system. You may want this, you may not. If you’re debugging a script that keeps acting up, the output cron mails will definitely be of some help.

Method #2 allows you to selectively redirect particular programs output to the bitbucket. /dev/null is the *NIX equivalent to a “Big Black Hole”™ on your computer. So if, say, you want the output from your alarm, but not from your email reminders just append >& /dev/null to the affected commands. Alternately, if you’d still like to receive mail about execution errors but not standard output you could append 1> /dev/null instead of >& /dev/null. This is an either/or situation. You just want one or the other, not both.

So there you go. Now you can set up all sorts of system automation without the pesky email notifications.