dru145 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I have a reoccuring problem with my Checkpoint FW-1 logfiles keep getting corrupt. Right now, I have this command fw log -n |more (-n says don't to resolve dns) in my .bash_profile so everytime I login it will tell me if the log files are corrupt or not. Well sometimes I don't login for a few days, so I lose 2 days worth of logfiles if they are corrupt. If everything is fine, then the command will just scroll through all of the log files (which are huge). Here is the error message that is returned when the log files do become corrupt
lvfile_open: failed to open logfile /etc/fw/log/fw.log log ptrs proble +m Failed to open logfile
Below is the script that I wrote that I thought would work, but it doesn't seem to be. Also, when the fw log -n is run is there a way to stop the process so that it doesn't stay open scrolling through the whole log file (by default this command will stay open showing all new log entries). I want to run this command every 30 minutes from cron and I don't want a bunch of these processes running in the background. Will this work: fw log |exit 1
#!/usr/bin/perl -w use strict; ############################################################ # # Script to check to see if the log files become corrupt # ############################################################ my $result; my $cmd1="fw log -n" ; my $from_addr="Root<root\@mysite.com>"; my $to_addr="Dru<dru\@mysite.com>"; #Run fw log command #$result=`$cmd1`; #If it fails, then send email if ($cmd1 =~ m/failed/){ open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Can't fork for sendmail: $!\n"; print SENDMAIL <<EOM; From: $from_addr To: $to_addr Subject: There is a problem with the firewall logs! EOM close(SENDMAIL) or warn "sendmail didn't close nicely"; exit 1 }
TIA
-Dru

Replies are listed 'Best First'.
Re: Mail me when Firewall Log Files Become Corrupt.
by VSarkiss (Monsignor) on Aug 31, 2001 at 03:54 UTC

    Hmm, this might just be a typo when you created the node, but you're setting $result and testing $cmd1.

    I haven't worked with the system you're using, but if I understand your writeup correctly, the fw log command won't stop until explicitly killed (ctrl-C or some such). You want to run it in a script and stop it after you get your output. The backticks won't do that, because they'll wait until the process has exited. You can either play shell games or do explicit fork and exec in your Perl program.

    Why I mean by "shell games" is to wrap a small shell script around the program like this:

    # Start fw log in background. # Note that all file descriptors are still shared; # you may need to close stdin if "fw log" tries to read it. fw log -n & # Wait 10 seconds. sleep 10 # Kill the child process and exit. kill $!
    I've presumed the 10-second sleep and that you're using a shell in which $! is the process ID of the last backgrounded program.

    To do it in Perl takes a little more work because you'll need to handle communication to the child process yourself. For ideas, look at the perlipc doc.

    Of course, if I've misunderstood how "Checkpoint FW-1 logfiles" work, you can ignore this node entirely. The PSI::ESP module only goes so far....

    HTH

Re: Mail me when Firewall Log Files Become Corrupt.
by Beatnik (Parson) on Aug 31, 2001 at 00:55 UTC
    Not really Perl (AFAIK) but nice for that stuff : SWATCH...

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.