SUMMARY: Online log file monitoring script?

From: ert weerr <>
Date: Thu Jan 27 2005 - 17:46:22 EST

> I have to write a script that online monitors a
> log file to check if a particular error message
> turns up there.
> The log file is quite big and I need to run some
> commands right after the message appears in the log.
> So, to grep for the message in every 1 second won't
> work, because at the time the script finished
> to grep the huge file some valuable seconds 
> would elapse.

Many thanks to everyone for your invaluable help!!!
The world would be a harsh place without you guys!


You can look at swatch and/or logcheck (or is it
swatch is more for continual monitoring (taking more 
immediate action), logcheck more for periodic. 
logcheck tracks where it left off in the file and
seeks to that point before continuing, so it may have 
the performance requirements you need.


logsurfer, logcheker, etc.


tail -f logfile | grep pattern |
while read line; do
	echo found it: $line
	#do other stuff

Run that as a daemon process. -f



and whatnot on or They
all have this similar functionality.



   tail -f logfile |
   while read LINE; do
	if echo $LINE | grep 'HELLO' >/dev/null; then
		I=$(($I + 1))
		echo "Encountered $I HELLOs"


tail -f /yourlog|grep yourmsg|while read line; do
echo execute commd using $line


There are others...


If you're thinking of perl, the File::Tail module can
help you out here. 
If not, you can still do something like 
tail -f <filename> | grep 
"mystring" in you script, but you'll have to watch out
for logfile 
rotation etc.



Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
sunmanagers mailing list
Received on Thu Jan 27 17:46:55 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:42 EST