dserodio has asked for the wisdom of the Perl Monks concerning the following question:
I'm new around here, so please excuse me if this is anwered elsewhere.
I'm writing a script that uses File::Tail to read lines from a log file.
However, if I exit (eg Ctrl-C) from the script, the most recently added lines won't be read, so I'd like to catch SIGQUIT and SIGTERM to read the remaining lines, no matter what File::Tail's interval is. How can I do that?
TIA
Re: Clean exit using File::Tail
by tadman (Prior) on May 16, 2001 at 02:26 UTC
|
There is an internal variable called %SIG which is used to
trap signals, such as:
sub QuitHandler { do_cleanup(); }
$SIG{'QUIT'} = \&QuitHandler;
You can catch everything, but be sure that you don't make
it impossible to KILL your program.
| [reply] [d/l] |
|
Cool, but how do I tell File::Tail to cleanup, ie read the remaining lines before exiting?
| [reply] |
|
Looking at the docs for File::Tail I might recommend you upgrade to version .98 if you have .60.
It appears that you could add the reset_tail=>0 parameter to the 'new' method, then close and reopen the file causing the mod to immediately reread the file. Also you could brutishly set maxinterval very low. Untested, though.
| [reply] |
|
What happens if your QuitHandler calls exit (and/or your File::Tail object goes out of scope)?
Update: You might also consider calling the nowait method.
--isotope
http://www.skylab.org/~isotope/
| [reply] |
|