Re: Monitor log file thru shell script

From: Jared Still <>
Date: Thu, 10 Jul 2008 14:12:02 -0700
Message-ID: <>

You can do this in Perl without the tail.

I have scripts that do this both on windows and linux, pure perl. - DL PDBA toolkit.

Scripts in question are and

Bear in mind that if you don't already have some familiarity with Perl, you may find installation and configuration somewhat difficult if you don't have the book to offer detailed instructions.

If you are already are comfortable with Perl, it should be no problem.

Unless of course you want to do this on Windows. The scripts all work, but installing DBD::Oracle on windows has become somewhat problematic.

If nothing else, you can look at the scripts to learn how to do 'tail -f' in Perl.


On Thu, Jul 10, 2008 at 1:09 PM, Yong Huang <> wrote:

> > 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
> Using tail, either tail -f or tail -[number], to check a specific string in
> a
> log file for notification purposes offers some advantages over scanning the
> file scheduled as a job (as most people do). Unless the file is recycled
> frequently, the file could become huge and so scanning the file from the
> beginning takes significant CPU and I/O (recording the last read line makes
> no
> difference). In addition, "tail -f" has the advantage that no scheduling is
> needed. By default, the interval it checks the file tail is 1 second. So
> notification is instantaneous. (On Linux you can change it with -s, but
> Solaris
> tail has 1 second hardcoded in source.)
> Shiva's command can be rewritten as:
> export err1=down
> tail -f testlogfile | perl -nle '$err1=$ENV{err1}; system("echo \"$_\" |
> mail
> -s "Found warning" shivaswamykr\") if (/$err1/)'
> There may be easier ways to do it. I can't get other suggested commands to
> work. But it may well be just me. My command is taken from my old note:
> Yong Huang
> --

Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist

Received on Thu Jul 10 2008 - 16:12:02 CDT

Original text of this message