Koozali.org: home of the SME Server

e-mail error report script

John Crisp

e-mail error report script
« on: January 20, 2003, 07:28:14 PM »
Hi,

I'm doing some debugging and want to run a short script in cron.d to notify me if a particular word or words appear in a log.

Unfortunately my programming skills are not brilliant. I tried something like the following. I get a mail in root with the log extract as I want it showing all the lines with the word PROBLEM (or whatever I am searching for), but the mail to john has a header of 'PROBLEM warning' with a message body showing the test "grep PROBLEM".

I guess the 'if' line should have something like &1 or similar to send the output to /dev/null or whatever (even though it's the bit that I want !) which stops it sending a mail to root.

Lord knows how I get the output sent to me properly. Pulling out my hair in frustration. Help..........!

B. Rgds
John


#!/bin/sh

#check if problem exists
if grep PROBLEM < /var/log/messages

#if problem exists, send what we found as body of mail to named recipient
then echo grep PROBLEM < /var/log/messages | mail -s "PROBLEM warning" john

#endif....
fi