Re: nohup job to monitor log files



On Apr 17, 12:19 pm, Bill Marcum <marcumb...@xxxxxxxxxxxxx> wrote:
On 17 Apr 2007 08:10:27 -0700, UnixNewbie



<vinayanrme...@xxxxxxxxx> wrote:

I'm sure this topic has been beaten to death on this forum. I'm here
since my searches have not found exactly what I'am looking for.

The requirement is this - I need to receive an email when an error
condition occurs in a log file. I have nailed together a script which
does this, but this script seem to be missing some pieces.

Tools available on the web are out of the question.

The way I have it right now is like this:

#!/bin/sh

#LogFileCheck.sh
.
.
<initialize variables,set paths >
.
<logic to get list of files that need to be monitored>
<logic to check if the log file is already being monitored>
.
.
nohup MonitorLogs.sh <log file path name>&
.
.
<script end>

#!/bin/sh

#MonitorLogs.sh

POC1=na...@xxxxxxxxxx,n...@xxxxxxxxxx,distrl...@xxxxxxxxxx

tail -f $LogFileName | while read n1 n2 n3 n4 n5 n6 n7 n8 n9 n10
do
if [ `echo $n7 | egrep '(XXXX[0-9][0-9][0-9]1I:)'` ] ||
[ `echo $n7 | egrep '(YYYY[0-9][0-9][0-9]1[^I]:)'` ] ||
[ `echo $n7 | egrep '(ZZZZ[0-9][0-9][0-9]1[^I]:)'` ]
then
LogFileName=Log-Monitor-`date '+%Y%b%d%H%M%S'`.log
LogFileName=/tmp/$LogFileName
echo $LogFileName > $LogFileName
echo $JVMLogFileName >> $LogFileName
echo ""
echo $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $n10 >> $LogFileName
mailx -s "`uname -n` -> Log File Exception" $POC1 < $LogFileName
fi
done

Now the problem I have with this script is that the main script kicks
off two processes - the tail process and the MonitorLogs.sh process.
How can I avoid the MonitorLogs.sh process being kicked off? Any tips
on improvinf this script is appreciated as well.

exec tail -f ...
You might use case instead of "echo $n7 | egrep", or combine the egrep
expressions into one. Or use "egrep -f", making it easier to change or
add expressions later.

--
"If you want to travel around the world and be invited to speak at a lot
of different places, just write a Unix operating system."
(By Linus Torvalds)- Hide quoted text -

- Show quoted text -

Good tip on "egrep -f". Thanks.

exec tail -f ... did not work though. Env is Linux and Hp-UX, bash.

.



Relevant Pages

  • script log file (how)
    ... The problem with my original script was that it didn't keep any logs of what ... creates a new log file every year so a single log file doesn't get too big ... if no one ever purges it. ... echo copy files into archive ...
    (microsoft.public.windows.server.scripting)
  • Re: nohup job to monitor log files
    ... condition occurs in a log file. ... but this script seem to be missing some pieces. ... echo $LogFileName> $LogFileName ... echo $JVMLogFileName>> $LogFileName ...
    (comp.unix.shell)
  • nohup job to monitor log files
    ... condition occurs in a log file. ... but this script seem to be missing some pieces. ... echo $LogFileName> $LogFileName ... echo $JVMLogFileName>> $LogFileName ...
    (comp.unix.shell)
  • redirect and "at"
    ... I have scrambled my brain trying to redirect the output of a script to a ... log file with the date the script ran in the file name. ... Do I have to direct each command to the log file or is there a way (inside ... *On-Line*) echo "The DBMS is Running now checking User Applications." ...
    (comp.unix.shell)
  • An ununderstanding shell scripting pb, please help...
    ... I come to yu cause i'm really lost. ... If i write a little script like this: ... # eval echo "\$Choix$n" ... env | egrep 'PATH' ...
    (comp.unix.shell)