Computing.Net > Forums > Unix > string in log for more than 20 min

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

string in log for more than 20 min

Reply to Message Icon

Original Message
Name: Cara
Date: October 11, 2002 at 23:03:12 Pacific
Subject: string in log for more than 20 min
OS: AIX
Comment:

Does anyone know how to find consecutive lines in a log file for more than 20 minutes?

I posted a question earlier to find 24 consecutive lines in a file because I thought they were coming out exactly every 50 seconds. However, this is not the case.

Here's a sample of the log file. I'm looking for the string 'Waiting in scheduler queue on server' repeated consecutively for more than 20 minutes.
I've tried uniq, grep, cut, sort,
tr ... |`expr...`

01:25:11 Beginning backup
01:27:33 /somefile.dat
01:32:20 Waiting in scheduler queue on server
01:34:08 Waiting in scheduler queue on server
01:36:02 Mounting tape ...
01:37:54 /somefile.dat
01:39:04 /somefile.dat
01:39:58 Waiting in scheduler queue on server
01:42:08 Waiting in scheduler queue on server
01:43:35 Mounting tape ...
02:01:11 /somefile.dat


Report Offensive Message For Removal


Response Number 1
Name: James Boothe
Date: October 13, 2002 at 08:33:02 Pacific
Reply: (edit)

It looks like your log file has only HH:MM:SS. If the log file spans multiple days, hard to tell if an entry is 30 minutes old or n days and 30 minutes old. In attempt to solve that problem, I process only the last 200 lines of the log file. This needs to be a figure that will get at least the last 30 minutes but not more than 24 hours. Processing more than the last 24 hours could produce false positives, and processing too few lines would result in failing to indicate a true positive. If 1000 lines were a daily average, I would suggest processing the last 500 lines.

I don't think we can check for consecutive entries because I see other non-related entries interspersed. I believe you are wanting the script to indicate when it sees a current (recent) "waiting" message, and also sees that these messages have been showing up for at least the last 20 minutes. My script defines windows of time. To be a "waiting" situation, it must see a log entry no older than 180 seconds AND must see at least one entry that is 20-25 minutes old. You need to put a top limit on it because you do not want it to indicate a waiting situation if it sees a recent entry and an entry 3 hours old, because that old entry would be for a prior event.

These windows of time are defined in the awk code as:

agedbeg=1500
agedend=1200
recent=180

which says that "recent" entries are those in the last 180 seconds, and "aged" entries are those that are 1200-1500 seconds old.

As currently coded, it does not care if there have been any entries between the "recent" entries and the "aged" entries. But if you wanted the script to do that, you could define a few more windows, such as 3-8 minutes ago, 8-13 minutes ago, etc, and the script could ensure that there has been at least one entry in each time window. Simple to do - just a few more lines of code.

The logic detects and handles midnight wrap around.

awk could print a message, but I figure you want to do something besides print a message (send and email?), so I exit awk with either a 0 or 1.

If you want to use other than ksh, you will probably need to recode the computation of csec which is the current hours, minutes and seconds converted into seconds.

# !/bin/ksh

date "+%H %M %S" |
read hr min sec
((csec=hr*3600+min*60+sec))

#echo "TEST: hr=$hr min=$min sec=$sec csec=$csec"

tail -200 cara.log |
awk -v csec=$csec 'BEGIN {\
#print "TEST: csec=" csec
agedbeg=1500
agedend=1200
recent=180 }
/Waiting in scheduler queue/ {\
gsub(":"," ")
tsec=$1*3600+$2*60+$3
if (tsec>csec)
cseca=csec+86400
else
cseca=csec
if (tsec+recent>=cseca)
{rcnt++;next}
if (tsec+agedbeg>=cseca && cseca>=tsec+agedend)
{acnt++;next}
} END {\
if (rcnt>0 && acnt>0)
exit 1
else
exit 0
}'
if [ $? -eq 1 ] ; then
echo "Waiting in scheduler queue detected"
fi
exit 0


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software