ChRy0 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!, i want to tail -f a access log and only print 'new' entries, not the entire logfile. I currently have this code, but that also prints the old contents which i don't want..
#!/usr/bin/perl use strict; use warnings; my $logfile = "/var/log/httpd/agent1_access.log"; open(FH,'<',$logfile) || handle_error(); # typical open call for (;;) { while (<FH>) { print "$_"; } # eof reached on FH, but wait a second and maybe there will be mor +e output sleep 1; seek FH, 0, 1; # this clears the eof flag on FH }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tailing a file without printing its entire contents
by BrowserUk (Patriarch) on Aug 07, 2014 at 12:00 UTC | |
by Anonymous Monk on Aug 07, 2014 at 12:17 UTC | |
|
Re: tailing a file without printing its entire contents
by roboticus (Chancellor) on Aug 07, 2014 at 12:04 UTC | |
|
Re: tailing a file without printing its entire contents
by Athanasius (Archbishop) on Aug 07, 2014 at 11:58 UTC | |
|
Re: tailing a file without printing its entire contents
by bulrush (Scribe) on Aug 09, 2014 at 13:02 UTC |