Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Watch log for string (tail -f)

by BrowserUk (Pope)
on Oct 11, 2012 at 20:19 UTC ( #998531=note: print w/ replies, xml ) Need Help??


in reply to Watch log for string (tail -f)

but it is not working

Is it sleeping on the job, or just not getting out of bed? :)

Does it hang; print 'not found'; explode in a rain of pink fairies?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


Comment on Re: Watch log for string (tail -f)
Re^2: Watch log for string (tail -f)
by hmb104 (Sexton) on Oct 11, 2012 at 20:25 UTC

    lol, yes it keep going and going and going. Any ideas about how to make it exit once 3 occurrences are cough in the tail -f command?

      tail -f doesn't end until you interrupt it. Try something like this:

      #! perl -slw use strict; my $pid = open TAIL, '-|', 'tail -f theLog' or die $!; my @matches; while( @matched <3 and defined( $_ = <TAIL> ) ) { push @matches, $_ if /the search term/; } kill 2, $pid; ## do something with the 3 lines in @matches.

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        Try this, May this will help

        use File::Tail; sub reading_updated_file { my $path=shift; my $count=0; my $file=File::Tail->new($path); while(defined (my $read=$file->read)) { if($read =~ /string_to_match/) { $count++; last if $count ==3; } print "here doing rest statements"; } } &reading_updated_file("path of file_to tail");
        This just really helped me. Note that @matches is declared but is interchangeably used as @matched, apart from that, this is really useful - thanks :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2014-07-31 00:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (242 votes), past polls