in reply to Creating a Deamonized Log Scraper



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