catphysh has asked for the wisdom of the Perl Monks concerning the following question:

I've searched pretty thoroughly and haven't located any threads regarding my dilemma. I have written a script that tails a Sendmail log file, slices, dices and inserts each line into a MySql DB. It works beautifully, and I'm surprised that it isn't a hog considering the amount of mail our mailers process.

I'm pretty much self taught, however, and can't be sure that I'm doing this properly. My doubt lies in the fact that once newsyslog rotates the mail log, my script is still tailing the old file.

I've considered splitting this script into two forked procs, one being a monitor and the other the log-tailing-sql-loader. The monitor could control a global variable based on the inode status of the rotating mail logs. The tailing proc could then be restarted depending on the status of the global variable.

I imagine it would work, but it seems like overkill for such a simple task. I'm curious as to whether or not anyone might have some other suggestions for me.
This is how I implemented my tail, btw...

## create fh open(LOG, "$log") || die "dead on file open: $!"; ## and jump to end seek(LOG, 0, 2); ## wait for line and match for (;;) { while (<LOG>) { ## SQL LOADER GOES HERE ## } ## don't want it to run away sleep 1; } ## close FH close(LOG);
Later ;-)

Replies are listed 'Best First'.
•Re: tail -F (not -f)
by merlyn (Sage) on Jun 03, 2002 at 14:28 UTC
Re: tail -F (not -f)
by Abigail-II (Bishop) on Jun 03, 2002 at 14:32 UTC
    One of the things you can do is to record the i-node number after opening the file, and just prior to your while (<LOG>) stat $log and check whether it has the same i-node number. If it hasn't, the log rotated, and you have to close and reopen LOG.

    Abigail

      Thanks to both of you, with a special thanks to Abigail. I have an innate ability to overcomplicate everything I do. Thanks for pulling me back to earth ;-)