in reply to Re: Logfile checking
in thread Logfile checking

I have created test logfiles that just have random messages with one or two that match the string in the config file. Currently I have a test config file that looks like such:
#format is:- # # #time_start:time_end:day_start:day_end:drive:path:filename:error 0000:2300:1:5:C:Temp:test.server.net.log:No messages have been receiv +ed from the remote host for the specified time period.
So the logfile has random strings and then a string that matches above.

Replies are listed 'Best First'.
Re^3: Logfile checking
by oko1 (Deacon) on Aug 17, 2010 at 01:45 UTC

    Barebones approach that you can extrapolate into what you're looking for:

    #!/usr/bin/perl -w use strict; open my $config, "config.cfg" or die "config.cfg: $!\n"; # Assuming the config file structure is one error per line my %errlist = map { chomp; $_ => 1 } <$config>; close $config; open my $log, "logfile.txt" or die "logfile.txt: $!\n"; while (<$log>){ chomp; /:([^:]+)$/; print "Error '$1' found on line $.\n" if exists $errlist{$1}; }

    In other words, you use the hash to store all your "valid errors", then check the actual errors against that hash. Fairly common algorithm, certainly in Perl.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf