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.
Asked
Active
Viewed 1,522 times
2
-
What you are describing is exactly what tail -f does internally, the only different being essentially that you are talking about using a longer delay time. If you still need to see all the lines, the hardware will limit you. – Gary Aug 10 '10 at 06:30
2 Answers
1
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
- 6,357
- 5
- 30
- 36
1
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
- 346,391
- 90
- 374
- 439