Re: nohup job to monitor log files
- From: UnixNewbie <vinayanrmenon@xxxxxxxxx>
- Date: 17 Apr 2007 13:42:56 -0700
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.
.
- References:
- nohup job to monitor log files
- From: UnixNewbie
- Re: nohup job to monitor log files
- From: Bill Marcum
- nohup job to monitor log files
- Prev by Date: looking for better way
- Next by Date: Re: Parsing in awk from one file to another
- Previous by thread: Re: nohup job to monitor log files
- Next by thread: How to delete *.class files from all subdirectories?
- Index(es):
Relevant Pages
|