new content notification from a log file

O

Oliver

dear all,

I have the following situation that I don't have a good solution:

One process periodically will append its output to a file (which is
not under my control), I want to write a ruby problem to detect and
report only the *new* stuff that went into the output file ... Besides
the brute force way such as opening the file and counting the lines
etc, is there a better solution to it?

Thanks for help

Oliver
 
G

Gary Wright

One process periodically will append its output to a file (which is
not under my control), I want to write a ruby problem to detect and
report only the *new* stuff that went into the output file ... Besides
the brute force way such as opening the file and counting the lines
etc, is there a better solution to it?

You can use File.stat('filename').size to get the number of bytes in
the file or .mtime to find the last modification time. If the bytes
and/or time changes you can then open the file and grab the new lines.

Gary Wright
 
O

Oliver

Thanks to both of you for the solution.

The double while loop seems a bit more concise, but it depends on
File#gets method handles the changing file content correctly. I will
give it a spin.

Best,

Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top