Re: nohup job to monitor log files



On 17 Apr 2007 08:10:27 -0700, UnixNewbie
<vinayanrmenon@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=name1@xxxxxxxxxx,name2@xxxxxxxxxx,distrlist@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)
.



Relevant Pages

  • Re: nohup job to monitor log files
    ... condition occurs in a log file. ... but this script seem to be missing some pieces. ... echo $JVMLogFileName>> $LogFileName ... You might use case instead of "echo $n7 | egrep", ...
    (comp.unix.shell)
  • 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)
  • 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)
  • Re: [Full-disclosure] reduction of brute force login attempts via SSHthrough iptables --
    ... Anyhow its no problem at all to modify, so if you dont like it, just dont use it. ... on a lame script like this as long as it WORKS and is not insecure. ... echo "~ sorting out ip by ip" ... # echo "not enough failed logins, probably no attack from: ...
    (Full-Disclosure)