Override MAILTO for a single crontab entry
We have a role account at work that has a pretty big crontab. Its MAILTO is pointed at a shared address, so that a number of us get notified if something fails.
I'd like to add an entry to this crontab, but I only want myself to be notified if something goes wrong. Is there a way to change MAILTO for this one entry, or otherwise accomplish my goal?
You can always just do:
MAILTO=you
* * * ... your cron job
MAILTO=normal.destination
You can always pipe all output to the mail command with the correct address in a subshell. As long as there is nothing on STDOUT or STDERR cron will not send the email
10 * * * * sh -c 'thisonecommand 2>&1 | mail [email protected]'
I can't recall if cron preparses the file to read in the environment vars, so I'm not sure if you can change MAILTO
multiple times in a single file. But you can always split it to another file and put it in /etc/cron.d/foo
with a [email protected]
.