Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
technique to 'tail' a file, I need a test to determine when the file has been closed (during log rotation, for example) and need to close/reopen the file name.seek(ML, 0, 1); # reset end-of-file error
Repeated 'Stat' has not worked for me.require "stat.pl"; ... for(;;) { open ML, "</var/log/local2" || die $!; &Stat(ML); $old_ML_size = $st_size; #seek(ML, 0, 2); # to EOF - Not, process from beginning for (;;){ &Stat(ML); if ($old_ML_size > $st_size) { print "closing the file\n"; last; #file closed and new one started }else{ $old_ML_size = $st_size; } while (<ML>){ another_line(); } sleep 5; seek(ML, 0, 1); # reset end-of-file error } close(ML); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading from a deleted file is futile
by Corion (Patriarch) on Feb 10, 2008 at 14:27 UTC | |
|
Re: Reading from a deleted file is futile
by jrtayloriv (Pilgrim) on Feb 10, 2008 at 14:42 UTC | |
|
Re: Reading from a deleted file is futile
by ysth (Canon) on Feb 10, 2008 at 23:03 UTC | |
|
Re: Reading from a deleted file is futile
by dynamo (Chaplain) on Feb 12, 2008 at 12:52 UTC |