Re: Monitor log file thru shell script

From: Stefan Knecht <>
Date: Tue, 8 Jul 2008 23:21:07 +0200
Message-ID: <>

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

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) :)



On Tue, Jul 8, 2008 at 10:57 PM, Shivaswamy / ಶಿವಸ್ವಾಮಿ <> 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"
> 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

Received on Tue Jul 08 2008 - 16:21:07 CDT

Original text of this message