log monitoring

Hi All;

I have a log file(dynamic) which i need to monitor; the format of the log

file is as follows

#Session ID    STATUS

The status can be one of the three /starting ;/loading ;/success

Example

#Session ID STATUS
ABC   /started.html
XYZ   /started.html
ABC   /loading.html
ABC   /success.html
XYZ   /loading.html
MNO  /started.html
XYZ   /loading.html
XYZ    /success.html
XYZ    /started.html
XYZ    /loading.html
MNO  /loading.html
MNO  /success.html
XYZ    /success.htm

The criteria to monitor is that NO Session ID is to have more than ONE

LOADING status

I need to run a script to monitor this every growing file.

I have written a script;I request you all to provide some inputs on the code
as which is the easiest way of running it every 90 seconds

My script does a while loop for entries (all session IDS) now the question is

that the file is quite big I dont want to check the entries.Can you help me

on Varibalising the file line count with each run and then the file needs to

process only the lines which have been added.

the code is a follows

while true
do
MAIL_RECEPIENT="root"
LOGDIR="/tmp_test"
EXTENSION=`date +%Y%m%d-%s`
awk '{print $1}' $1|sort -u|while read IN;                                    

           do

grep "$IN" $1; done|grep -i -A2 "l
oading" |uniq -d > $LOGDIR/log.$EXTENSION

if [ -s $LOGDIR/log.$EXTENSION ]
then
cat $LOGDIR/log.$EXTENSION|while read SD
do
sid=`echo $SD|awk '{print $1}'`
status=`echo $SD|awk '{print $2}'`
echo "Session ID $sid has an issue.Please check"|mailx -s "Session ID $sid 

having issue"  $MAIL_RECIEPIENT
echo "Session ID $sid has an issue.Please check"
done
fi
sleep 90
done

You could do a `wc -l` and use the output with tail to get the updated lines.

In bash

$ cat buf
1
2
3
$ wc -l buf
       3 buf
$ n=$(wc -l buf| awk '{ print $1}')
$ cat buf
1
2
3
4
5
6
$ tail +$(($n+1)) buf
4
5
6

If the file is being appended for every run and only the appended lines need to be processed. Suppose run1 is the file of the first run and run2 is the file of second run which has same content as run1 and some extra appended lines. The appended lines can be brought into a separate file and this file can be processed.

The command and ouput is :

bash-3.00$ cat run1
Hi
Bye
bash-3.00$ cat run2
Hi
Bye
See
You
bash-3.00$ tail -n $((`cat run2 | wc -l` - `cat run1 | wc -l`)) run2
See
You
bash-3.00$

This command gives the extra lines from run2. Hope this helps.

Thanks.