How to stop a cron job sending email
kauer at biplane.com.au
Fri Oct 31 14:37:05 UTC 2008
On Fri, 2008-10-31 at 15:21 +0200, Johann Spies wrote:
> It can be something like:
> fetchmail: No mail for johann.spies at wo.co.za at mail.wo.co.za
> fetchmail: No mail for security at alterit.co.za at alterit.co.za
> fetchmail: No mail for webmaster at alterit.co.za at alterit.co.za
> fetchmail: No mail for johann.spies at alterit.co.za at alterit.co.za
The right way to deal with this is to change your script so that it
pipes its results into (say) grep:
killall -q fetchmail
/usr/bin/fetchmail | grep -iv "No mail for "
That way there will be no output generated if everything works as
With egrep you can scan for more than one expected result. Or you could
use a chain of greps.
killall outputs nothing if it successfully kills things. "-q" tells it
not to report that no processes were killed. If anything else happens,
you will be informed. There may be a similar switch for fetchmail, which
would save using grep.
If expected messages are going to stderr instead of stdout you have to
use a syntax that is slightly less well known. For example, to capture
the "no process killed" message from killall (instead of using "-q"):
killall telnet 2>&1 | grep -iv "no process killed"
One day your script will output something different: "fetchmail: Oops!
Major problem! You have eight hours to act before your hard disk is
wiped and your pets are shaved!"
Because that doesn't match the regexp, it will be output and thus mailed
to you in time for you to save the day.
PS: Untested code above - just typed in, never run.
Karl Auer (kauer at biplane.com.au) +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/ +61-428-957160 (mob)
GPG fingerprint: DD23 0DF3 2260 3060 7FEC 5CA8 1AF6 D9E3 CFEE 6B28
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 189 bytes
Desc: This is a digitally signed message part
More information about the ubuntu-users