Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

difference in time for syslog cron script

Status
Not open for further replies.

pcorchary

MIS
Feb 23, 2002
60
US
I am in search of a portable (sh) method for differential times, that includes dates. Essentially I need an accurate way to determining what time it was "N" minutes ago ...

The core problem is to scavange Solaris syslog /var/adm/messages for certain things, but only from the entries of of the past N minutes (probably 10 minutes), via a cron job ...

I've seen some fancy perl that i can't use. awk might do it, but I can't quite gte it working. And I've seen lots of DATE difference scripts, but I really need TIME dfference, and of course since I'm working with cron, I need to compare to that date format ... "May 8 01:59:59".

ANY help appreciated.
 
Do these log files get deleted regularly?

An alternative would be to record the last line processed in a file, so that when you next run the program, you can skip all the lines in the log file which you've processed already.

#!/bin/awk -f
BEGIN {
# where did we get to last time?
getline prev < &quot;prev.txt&quot;
}
FNR > prev {
# do stuff with lines appended since last time
}
END {
# record where we got to for next time
print FNR > &quot;prev.txt&quot;
}
 
The log files do NOT get trimmed -- the rotate semi-regularly, but /vart/adm/messages in our environment are kept as messages.0, messages.1, etc. for at least 6 months.

Recording that last line processed is an interesting thought. I also considered using /bin/logger to write a marker line into the log itself for the script to operate from.

Ideally I'd still like to go by the date stamp :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top