views:

87

answers:

2

Hi,

I am monitoring a log file by doing "TAIL -n -0 -F filename". But this is taking up a lof of CPU as there are many messages being written to the logfile. Is there a way, I can open a file and read new/few entries and close it and repeat it every 5 second interval? So that I don't need to keep following the file? How can I remember the last read line to start from the next one in the next run? I am trying to do this in nawk by spawning tail shell cmd.

+1  A: 

You won't be able to magically use less resources to tail a file by writing your own implementation. If tail -f is using resources because the file is growing fast, a custom version won't help any if you still want to view all lines as they are being written. You are simply limited by your hardware I/O and/or CPU.

Gary
+1  A: 

Try using --sleep-interval=S where "S" is a number of seconds (the default is 1.0 - you can specify decimals).

tail -n 0 --sleep-interval=.5 -F filename

If you have so many log entries that tail is bogging down the CPU, how are you able to monitor them?

Dennis Williamson