Is there a way/tool to tail
or watch
a logfile and report the amount of lines it grows?
E.g. I want to see the amount of new entries in mysql.log every 3 seconds.
watch wc -l /path/to/log.log1
shows only acumulated amount. I'd prefer not to truncate
the log inbetween.
All you have to do is redirect the file into
wc
and it will only show what was added rather than the total.The
<
makes all the difference.Here's some quick-and-dirty perl to do what you want:
Here's the output of it running in one window:
And here's the commands I ran in another window to generate the output above:
Hope that helps...
I don't know any standard tool but you could use the following Python script:
To test:
It is not perfect because it cannot "monitor"
STDIN
or detect when the file has been replaced (the--follow=name
tail's option.And here is a bash script:
It has the advantage of being usable directly in the shell, provided you are not alergic to ";" ;)