Friday, March 5, 2004

cron mail

Whenever you run a command in your crontab, if there is any output, it will send you an email. This is sometimes a good thing, but sometimes not, depending on how often the job runs and what kind of output it generates.



If you just want to get rid of "normal" output, and only have it email you if there is error output, you can redirect stdout to /dev/null, like thus:


5 * * * * yourcommandhere >/dev/null

This sends normal output to the bit bucket, but anything the command puts out the stderr (the error output) will get emailed you.



If you want to ignore all output, error and normal, you can "tie" the error output to go to the same place the normal output goes, like thus:


5 * * * * yourcommandhere >/dev/null 2>&1


Now you won't get any email.



Another option for turning off email is to set the MAILTO variable to NULL. See the manpage for more discussion on this option.




1 comment: