Greetings Bretheren,

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


I would like to eventually substitue snmp traps to a central console in lieu of emails, but one hurdle at a time. Again any thoughts, opinions or advice would be very much appreciated.

Thanks,
Pat

In reply to Creating a Deamonized Log Scraper by quasimojo321

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.