Re: How to stop a cron job sending email



On Fri, 2008-10-31 at 15:21 +0200, Johann Spies wrote:
It can be something like:

fetchmail: No mail for johann.spies@xxxxxxxx at mail.wo.co.za
fetchmail: No mail for security@xxxxxxxxxxxxx at alterit.co.za
fetchmail: No mail for webmaster@xxxxxxxxxxxxx at alterit.co.za
fetchmail: No mail for johann.spies@xxxxxxxxxxxxx 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:

#!/bin/sh
killall -q fetchmail
/usr/bin/fetchmail | grep -iv "No mail for "

That way there will be no output generated if everything works as
expected.

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.

Regards, K.

PS: Untested code above - just typed in, never run.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer@xxxxxxxxxxxxxx) +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

Attachment: signature.asc
Description: This is a digitally signed message part

--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users


Relevant Pages

  • RE: configuring dial-up for extreme novices (i.e. Mom).
    ... I'm going to use userland ppp and postfix. ... > your Mom a script to run which will start fetchmail, ... Then have commands in script to kill fetchmail and user ... sudo /usr/sbin/ppp -quiet -background myisp ...
    (freebsd-questions)
  • Re: strange email behavior
    ... > different computer you use fetchmail to connect to the ... > poll your POP3 mailbox manually to debug your problem. ... I saw that the script was calling /etc/fetchmailrc, ... instead of my user's mbox. ...
    (RedHat)
  • Re: strange email behavior
    ... > startup script for fetchmail that might have something to do with it. ... Since running fetchmail as root is such an unbelievably bad idea that I ... the init script that you've got. ...
    (RedHat)
  • Re: Fetchmail revisited
    ... > fetchmail supports that. ... a script written by you rather than handing it to the MTA untouched. ... AND I did help the sorting a bit because at my ISP I'm allowed to ...
    (alt.os.linux.suse)
  • RE: configuring dial-up for extreme novices (i.e. Mom).
    ... your Mom a script to run which will start fetchmail, ... Then have commands in script to kill fetchmail and user ... configuring dial-up for extreme novices (i.e. Mom). ... To unsubscribe, ...
    (freebsd-questions)