We help IT Professionals succeed at work.
Get Started

Log monitoring script

Peddu_bhanu
Peddu_bhanu asked
on
339 Views
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

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

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2010
Commented:
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