Hi chaps,
I need a script to search a log file (whose name is DD-MM-YYYY.log)
for an error (for example "AN ERROR!").
However, even though the script rolls over each day, the files can get
very large, and errors occur often.
This script will be run at regular intervals (every 15 mins I reckon
at the mo) and needs to return something like a 1 if an error string
was found and a 0 if not. This value in turn will be used by the
alerting package to fire off alerts and poke things to get it working
again.
Now, i've got all that working more or less (getting the date bits to
auto-fill the filename is being a pain) expect for one important bit.
In my script, the log file is opened and then searched line by line,
and if an error is found, 1 is returned. The problem is that it
restarts from line 1 each time it's fired, so basically we are always
getting alerts, even for alerts we have already been told about.
What I need is some way to store the last line that was checked by the
script, and to start from the following line on the next check. I
guess this would in turn have to save the line number to a text file
and read it back when the check starts next.
Any ideas how I can do the latter bit? Finding the line number and
then starting from that point again ?
Olly