Configuring crontab mail destinations with MAILTO

When scripts executing from cron write to stdout or stderr, the results are emailed to the user the job is running in the context of. One way to control where the mail is sent is by adding a “MAILTO” line to the top of the crontab entry for the user that is running the cron job. Here is an example:

$ crontab -l
MAILTO=matty
* * * * * echo “hi”

Each time this job runs, the user matty will get emailed with the results of the script. You can also use /etc/aliases to assist with this on a global scale, but sometimes that isn’t an option.

Leave a Reply

Your email address will not be published. Required fields are marked *