Mark
Try using a few script files for this!!! cron a /path/to/launch.sh which is like
#/bin/sh /path/to/script.sh > /tmp/output.txt pause 10 mail -es "mail subject" him@there.com </tmp/output.txt # clear up ( only after the testing is OK !!! ) rm /tmp/output.txt
but it looks like there might be an error because you kill the mail server and the set it on its way. Then immediately send an email, so the server might not be started up in time.
HTH Keith
________________________________
From: main-bounces@lists.alug.org.uk on behalf of Mark Rogers Sent: Tue 30/10/2007 6:03 PM To: ALUG - mailing list Subject: [ALUG] Email from cron scripts
I have the following in my crontab: */5 * * * * /path/to/script.sh | mail -es "mail subject" me@example.com
What "script.sh" does is check whether the mail server is running correctly. If it is, then it sends a message to stdout and exits. If it is not, then it sends a different message to stdout, then restarts the mail server, then exits.
If the mail server is OK, the output to stdout is captured and emailed via cron correctly.
If the mail server is not OK, it is successfully restarted but the mail does not get sent. In fact, the script never exits: $ps ax [..snip..] 28907 ? S 0:00 /USR/SBIN/CRON 28908 ? Ss 0:00 /bin/sh -c /path/to/script.sh | mail -es "mail subject" me@example.com 28912 ? S 0:00 mail -es mail subject me@example.com 28941 ? S 0:00 /usr/sbin/sendmail -i -FCronDaemon -oem root [..snip..]
Clearly "mail" or "sendmail" (in my case the Postfix version) doesn't like the mail server being restarted under its feet like this.
How can I get around this? I'd like to capture all the output from script.sh (including the output from the mail server restart) if I can.
If it's relevant, in this case restarting the mail server means stopping (in this order) postfix, clamav and dspam, then starting them again in reverse order. The problem I'm having is dspam dies sometimes (once every couple of days) and the script is intended to work around this until I fix it.
-- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555 Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG
_______________________________________________ main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!