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:
- At the top of the crontab file, place the following command:
MAILTO=”" (That’s a null or just two quotes back to back) - Redirect the output of the offending program in your crontab
20 6 * * 1-5 /home/grim/alarm >& /dev/null
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.
Posted by Philip McClure in Linux on March 09, 2004