I have written a script to look for a specific string occurring within a log on a windows system. The log fills up very quickly and therefore rolls over (rotates) often. For some reason though, while my script is running, the file will not roll-over, presumably because the rolling mechanism cannot get a suitable lock on the file. I have tried using File::Tail and POE::Wheel::FollowTail and both work fine except for not allowing the file to roll-over.

As an experiment, I have tried using SFU's "tail -f" and that doesn't keep the rollover from occurring, but of course also doesn't follow the new file when a roll-over does occur.

I can think of several ways to periodically release and re-open the file, but it is too easy to miss an occurrance of the issue that way.

I will paste the applicable code from both methods I have tried below.

Any enlightenment would be greatly appreciated,
-Frd

File::Tail code:

my $file=File::Tail->new(name=>"$SEARCH_LOG", maxinterval=>10); LogIt("Initiated 'tail' ... reading file '$SEARCH_LOG':\n"); LogIt(" ... Looking for '$STRING'\n"); while (defined(my $line=$file->read)) { LogIt("Read line: $line"); next unless ( $line =~ /$STRING/ ); LogIt("That Line MATCHES SEARCH STRING: '$STRING'\n"); lock($occurred); $occurred ++; LogIt("$line"); LogIt("Increasing OCCURRED flag to '$occurred'"); }

POE code:

POE::Session->create( inline_states => { _start => sub { $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Filename => "$SEARCH_LOG", InputEvent => "got_log_line", ResetEvent => "got_log_rollover", ); }, got_log_line => sub { my $line = $_[ARG0]; LogIt("Read line: $line"); return unless ( $line =~ /$STRING/ ); LogIt("That Line MATCHES SEARCH STRING: '$STRING'\n"); lock($occurred); $occurred++; LogIt("$line"); LogIt("Increasing OCCURRED flag to '$occurred'"); }, got_log_rollover => sub { LogIt("Log rolled over.\n"); }, } );

In reply to Tail'ing a log that frequently rolls over by frd1963

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.