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 ;-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.