Just to wrap this one up for posterity (for now at least) here is the final beta code for the little project. MAJOR concerns not withstanding, the code seems to function the way it's supposed to. It starts up 7 logfile scrapers that run continously in the background looking at the last line of each logfile and signaling when it sees something it doesn't like. I will be adding code to track and kill the children should the need to arise (probably use ctrl C to send a sigkill as I have seen previously demonstrated on this site.) As well I will benchmark the activity of this deamon and let you know how it afffects a copy of our live environment. I will also try to address concerns fronted by members regarding race conditions and resource utilization problems. As you can see I have implemented some of your suggestions already...
Without further ado, here is the code:
#!/usr/bin/perl -w
#
use strict;
use Parallel::ForkManager;
use File::ReadBackwards;
#
my (@DBLOG,@SKIPCODES,$logline,$line,$list,$node,$pm,$i);
#
@DBLOG=qw( /bd01/systems/systems.lg /ad04/orders/orders.lg /bd02/maste
+r/master.lg /cd01/billing/billing.lg /cd02/audit/audit.lg /bd01/custo
+m/custom.lg /bd01/apprules/apprules.lg );
#
@SKIPCODES=qw( lots of inconsequential stuff that I want to ignore );
$list = join ("|", map {quotemeta} @SKIPCODES);
$node=`uname -n`;
$pm=new Parallel::ForkManager(7);
foreach ($i)
{
my $pid=$pm->start and next;
while (1==1)
{
$line = File::ReadBackwards->new( $i ) || die "Can't read from
+ $i:$!";
$logline = $line->readline;
next if $logline =~ /\W$list\W/;
next if $logline =~ /^$/;
system ("echo \"There is a problem with database logfile: \"$i
+\" on $node\. Here is the error\:\n\n $logline\" | mailx -s \"PROGRE
+SS DATABASE PROBLEM!!!\" psmith\@xxxxx\.com");
system ("sleep 120");
}
}
Hope this is of some use to someone at some point. Code On!!!
Pat
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.