quasimojo321 has asked for the wisdom of the Perl Monks concerning the following question:
I am a creating a deamonized perl executable to constantly scrape the contents of a databse logfile. When all is said and done I will actually have to scrape about 124 of these logfiles. My initial thoughts were to use File::ReadBackwards to scrape the last line of every logfile. I would then parse that single line file for known error codes. If it finds something interesting, it'll mail a warning and the line to a recipient. My question is this... I would like to start the perl deamon (let's refer too it as logdbd.pl hereafter) once and then have it spawn a sub-proccess for each database log that I want to scrape.
I know that I must use fork and exec to do this but I've gotta say that I don't know exactly what I am doing. Should I create a main loop that does the last line fetch and scrape and then create a sub that iterates through my logfile array and re-executes the main loop using the next logfile name as the new argument? Remember that the the execution of the main program should be endless. That being the case would I ever be able to spark up the next child proccess seeing as the first one to be started never exited?
I am only a fair to middling perl coder, and this is my first foreray into a complex program in any language. Any help would be greatly appreciated. My Sample code is as follows:
#!/usr/bin/perl -w # use strict; use File::ReadBackwards; my (@DBLOG,@SKIPCODES,$line,$logline,$list); @DBLOG=qw( /bd01/systems/system.lg /ad04/orders/orders.lg /bd02/master +/master.lg /cd01/billing/billing.lg /cd02/audit/audit.lg ); @SKIPCODES=qw( (43) (334) (354) (8826) (3803) (50) (5140) ); $list = join ("|", map {qoutemeta} @SKIPCODES); $node=`uname -n`; foreach $i (@DBLOG); { unless (defined ($pid = fork})) { die "Can't Fork Proccess: $!"; } unless (defined ($pid)) { LOGSCRAPE ($i); } ################################ sub LOGSCRAPE { $line = File::ReadBackwards->new( '$_' ) || die "Can't read from $_: + $!"; $logline - $line->readline; while ($logline) { next if $logline =~ /\W$list\W/; next if $logline =~ /^$/; system (echo \"There is a problem with $_ on $node. Here is the +error code:\n\n $logline\" | mailx -s \"PROGRESS DATABASE PROBLEM!!!\ +" psmith\@xxxx.com"); system ("sleep 60"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating a Deamonized Log Scraper
by ehdonhon (Curate) on Feb 07, 2002 at 23:17 UTC | |
|
Re: Creating a Deamonized Log Scraper
by rjray (Chaplain) on Feb 08, 2002 at 00:12 UTC | |
|
Re: Creating a Deamonized Log Scraper
by Anonymous Monk on Feb 08, 2002 at 03:14 UTC | |
by ehdonhon (Curate) on Feb 08, 2002 at 17:36 UTC | |
|
Re: Creating a Deamonized Log Scraper
by quasimojo321 (Initiate) on Feb 08, 2002 at 21:27 UTC |