We help IT Professionals succeed at work.
Get Started

Log monitoring script

Peddu_bhanu asked
Last Modified: 2013-12-26
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

#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
EXTENSION=`date +%Y%m%d-%s`
awk '{print $1}' $1|sort -u|while read IN;                                    


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

if [ -s $LOGDIR/log.$EXTENSION ]
cat $LOGDIR/log.$EXTENSION|while read SD
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"
sleep 90

Watch Question
Top Expert 2010
This problem has been solved!
Unlock 2 Answers and 2 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE