Hi I am trying to read from /var/log/messages
but the script will finish…
ok ok… what I am trying to do is open the log or logs and wait for a
phrase of my choosing to appear then do something…
I know the regex part and how to use it… I know how to open files to
read… I just don’t know how to read a file and tell ruby to keep
reading it for new entries on it…
Thanks.
On Thu, 12 Jun 2008, rek2 wrote:
Hi I am trying to read from /var/log/messages
but the script will finish…
ok ok… what I am trying to do is open the log or logs and wait for a
phrase of my choosing to appear then do something…
I know the regex part and how to use it… I know how to open files to
read… I just don’t know how to read a file and tell ruby to keep
reading it for new entries on it…
Im guessing you going to have to sleep and poll the modification
timestamp on the file at regular intervals to see if its changed. If it
has, and you have the file open, you can read bytes until you get EOF,
print them out and go back to sleep again.
It might be useful to read the C source code to things like tail.
–
Eno wrote:
Im surprised ruby does not a lib for this 
what about using seek like seek to one line before EOF… then repeat
? if is save for ruby to run forever till I do a kill -9?