Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Clean exit using File::Tail

by dserodio (Novice)
on May 16, 2001 at 02:01 UTC ( [id://80737]=perlquestion: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
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.
      Cool, but how do I tell File::Tail to cleanup, ie read the remaining lines before exiting?

        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.

        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/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://80737]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 02:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found