leostereo has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks: I was tryng to feed a file with last ip granted by my dhcp server. Trying to inspect dhcpd.log file using tail, I tryed a simple code from documentation. test.pl

#!/usr/bin/perl use File::Tail; $file=File::Tail->new("/var/log/dhcpd.log"); while (defined($line=$file->read)) { print "$line"; }

Here dont get any output nor error so, then I tryed other piece of code that works ok. test2.pl

#!/usr/bin/perl -w use File::Tail; sub find_aaa_name { return '/var/log/dhcpd.log'; } my $file = File::Tail->new( name =>'/opt/dhcp_tail/dummy.txt', interval => 1, maxinterval => 1, resetafter=> 5, name_changes=> \&find_aaa_name, ignore_nonexistant => 1 ); while (defined($line = $file->read)) { print $line,"\n"; } 1;
Can someone give me a clue? What is the difference ; why test1 dont work and dont print even an error message and test2 works ok ? I hope it can be usefull to someone. Regards, Leo.

Replies are listed 'Best First'.
Re: File::Tail can not get output
by toolic (Bishop) on Oct 08, 2015 at 20:57 UTC
    Your test1 "works" for me. When I run it on an existing file (which has not been updated for many days), it shows me all the lines in the file, but it takes about a minute before I get any output. This roughly corresponds to the default maxinterval of 60 seconds. Are you sure you waited long enough?

    When I change the code to use maxinterval=1, like your test2, I see the output much sooner, as expected.

      you were right .... it was working , just need to wait a little bit more or change defaults Thanks
Re: File::Tail can not get output
by Discipulus (Canon) on Oct 09, 2015 at 08:12 UTC
    Can be a buffer problem? I mean the OS writes effectively to a file after some buffer is full. The process that writes this log can do similar things. It happened to me with some nasty ms application logs.

    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: File::Tail can not get output
by stevieb (Canon) on Oct 08, 2015 at 20:36 UTC
    I'm not in a position to review docs or to test this right now, but does adding use warnings; and use strict; to the top of your script produce any output? You should always use these pragmas.