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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eno wrote:> 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. > > > >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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---