Re: Monitor log file thru shell script

From: Stefan Knecht <knecht.stefan_at_gmail.com>
Date: Tue, 8 Jul 2008 23:21:07 +0200
Message-ID: <486b2b610807081421j1a8b3586w939c6c114649e2a@mail.gmail.com>


The problem lies in the way tail -f works. The mail command never gets an EOF that would trigger it to send the mail. Your script isn't going to work this way.

Try something along the lines of:

for i in `tail -f alert_M.log | grep log`; do mail -s foo root_at_localhost<<_EOF found $i in logfile
.
_EOF
done

Also, make sure your /etc/mail.rc file doesn't containt set askcc -- otherwise mail will sit there waiting for you to enter the CC address (which you can't since mail isn't attached to a tty) :)

Cheers

Stefan

On Tue, Jul 8, 2008 at 10:57 PM, Shivaswamy / ಶಿವಸ್ವಾಮಿ < shivaswamykr_at_gmail.com> wrote:

> Hello.
>
> I am attempting to look for a pattern in the continuously growing log file
> and mail me if match is found. (on Linux). But I am having problem.
> This is the part of the shell script
> export err1=down
> tail -f testlogfile | egrep -n "${err1}" | mail -s "Found warning"
> shivaswamykr_at_gmail.com
> As you see I am using tail -f and egrep. When I run only tail -f & egrep
> part on the prompt on my testlogfile, I am able to see the output from
> egrep.
> But when I pipe it to mail, and run it on nohup on a shell script, nothing
> happens. I can see that mail process is in T state, meaning it is stopped.
> If I kill my shell script running in the background, I get the email
> notification, as expected.
> What happens here? How I can get the notification, without killing the
> process?
> If you could please help, I appreciate it.
> Thanks,
> Shiva
>

-- 
=========================

Stefan P Knecht
Senior Consultant
Infrastructure Managed Services

Trivadis AG
Europa-Strasse 5
CH-8152 Glattbrugg

Phone +41-44-808 70 20
Fax +41-808 70 12
Mobile +41-79-571 36 27
stefan.knecht_at_trivadis.com
http://www.trivadis.com

OCP 9i/10g SCSA SCNA
=========================
--
http://www.freelists.org/webpage/oracle-l
Received on Tue Jul 08 2008 - 16:21:07 CDT

Original text of this message