I have several cron jobs that run (in /etc/cron.daily, /etc/cron.hourly, /etc/cron.weekly, etc.) and email root@localhost with the results. I'd like to stop those emails if the jobs are succeeding, and only email on error (which I understand can be done by redirecting stdout to /dev/null). I understand how to do that for individual cron jobs, but the scripts in those special directories are run using run-parts. What is the best way to suppress success emails for those scripts?

link|improve this question

feedback

1 Answer

You should send successful email notifications to /dev/null so they disappear.

But you want to see unsuccessful email notifications.

This means you need to first direct stdout to /dev/null and then direct /dev/stderr to stdout

try changing the redirection part of your cronjobs to

>/dev/null 2>&1

See this link

link|improve this answer
Wouldn't that suppress the error emails too (because they wouldn't produce any output)? Also, I need to do this for my cron.XXX directories which use run-parts, so it's not as simple as redirecting for individual scripts. – jrdioko May 29 '11 at 1:47
No the idea is that stderr is thrown away then stderr is redirected to stdout. I'm not sure what run-parts is, but however it works redirection of stdout and then stderr seems to be the way. – pavium May 29 '11 at 2:01
Aha, I googled run-parts. That does complicate the issue, doesn't it. Maybe you should avoid run-parts and invoke each script separately. – pavium May 29 '11 at 2:05
Ah ok, I understand. run-parts runs all scripts in directories like /etc/cron.daily, so the trick is passing along the redirection to the individual scripts it is running. – jrdioko May 29 '11 at 2:06
I think so. I couldn't find anything about redirecting all output from run-parts (not even in the man page I just discovered I have. – pavium May 29 '11 at 2:14
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

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