Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have multiple cron job entries configured under a single account:

0 0 * * * /foo/foo.sh
0 2 * * * /foo/foo2.sh
0 4 * * * /foo/foo3.sh

Right now, if any of these encounter an error, an email is sent to the user account. Can I configure cron to send a notification to a different email address depending on which entry encounters the error?

For example, if an error occurs while running /foo/foo.sh send to bob@bob.com. If an error occurs while running /foo/foo2.sh send to joe@joe.com.

I know I can set MAILTO=someaddress@example.com but I think that's for ALL cron entries (for the account I'm logged in as)... I don't think that's a per-entry setting.

Hopefully this makes sense. Thanks. :-)

share|improve this question

2 Answers 2

up vote 6 down vote accepted

It it perfectly Ok to use MAILTO= per-entry, i.e.:

MAILTO="address1"
0  0 * * * /foo/foo.sh
MAILTO="address2"
0  2 * * * /foo/foo2.sh
MAILTO="address3"
0  4 * * * /foo/foo3.sh
MAILTO="address4"
0  6 * * * /foo/foo4.sh
0  8 * * * /foo/foo5.sh
0 10 * * * /foo/foo6.sh

And so on.

Cheers,

share|improve this answer
    
Ah, I didn't know that was possible. That's exactly what I'm looking for. Thank you! –  Mike B Aug 29 at 16:13

I am not sure if this is what you are looking for. From that answer, I see it as,

ORIGMAILTO="$MAILTO"
MAILTO=you
* * * ...  your cron job
MAILTO="$ORIGMAILTO"
share|improve this answer

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.