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 ;-)