Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Another approach to those suggested so far, is to use the feature that cron emails the user who is running the job, so make another user just for this job, and forward its emails to you. –  Hayden Thring Apr 25 at 3:50
add comment

3 Answers 3

up vote 14 down vote accepted
ORIGMAILTO="$MAILTO"
MAILTO=you
* * * ...  your cron job
MAILTO="$ORIGMAILTO"

I think that works... Otherwise, you can always just do

MAILTO=you
* * * ...  your cron job
MAILTO=normal.destination
share|improve this answer
    
Did the people who upvoted this really test it out? If so, what cron implementation? –  user1338062 Sep 26 '12 at 6:57
add comment

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 otheraddress@foo.com'

share|improve this answer
    
This doesn't work -- the "mail" command sends regardless of whether or not it gets output. So I get an empty message on success, whereas what I want is no message on success. –  mike Jul 1 '09 at 17:46
1  
Nice! And to avoid empty emails from mail command, use this parameter: -e (or -E for some..) –  user58599 Oct 28 '10 at 20:17
add comment

I cant recall if cron pre parses the file to read in the environment vars, so im 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 MAILTO=some@email.tld

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.