I want to be able to see how many lines were added to a file since the last quering without reading the whole file again.
Something like :
ptail my_file | fgrep "[ERROR]" | wc -l
A solution in simple Perl would be prefered, since I don't have an easy access to a compiler.
Although it consumed the lines for other purposes, I have written code which does essentially this before.
All you need to do is record the byte offset (with tell) and inode (with stat) for each file after the tail is complete. The next time it's run against the file, first check the inode (with stat) again. If the inode has changed or the file is smaller than the recorded offset, then it's a different file (deleted and recreated, log got rotated, etc.), so you should show it from the beginning; otherwise, seek to the recorded offset and display it from there.
since does exactly that although it is in C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With