I suggest a different approach...
note: I have not tested this code. The concept has worked elsewhere, but there may be typos or incompatibility with File::Tail.
#!/usr/bin/perl use strict; use warnings; use File::Tail; my $cur_filename = $ARGV[0]; { my $file = File::Tail->new( name => $cur_filename, maxinterval => 3, adjustafter => 2, tail => -1, ); eval { local $SIG{INT} = sub { die "interrupted\n"; }; while ( defined( my $line = $file->read) ) { print $line; } }; if($@ eq "interrupted\n") { open(FILE,"/tmp/filename") || die "Cannot open file:$!"; $cur_filename=<FILE>; close(FILE); redo; } else { die "$@"; } }
You may never print the last line of the file if the interrupt arrives after a line has been added and before it has been printed: an interval including a significant number of CPU cycles. This risk can be mitigated somewhat by having the external program redirect log entries to the new file then waiting briefly before interrupting this program.
In reply to Interrupting File::Tail with a signal handler
by ig
in thread File::Tail issue..
by tuxtoti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |