#!/usr/bin/perl # logreporter - Brian Edmonds 94Oct27 # template file directives: # # [IGNORE] # - all lines matching patterns until the next directive are ignored. # # [REPORT -> report message here] # - if the pattern following this directive matches a line, the # report message will be output; $d is bound to the first 15 # characters of the matched line (the timestamp for syslog) when # the report message is evaluated. # # [COUNT -> report message here] # - the number of lines in the file which match the pattern following # this directive will be reported using the given report message, # if greater than zero; $n is bound the the number of matching lines # when the report message is evaluated. # # [SUM $X -> report message here] # - the numeric subfield $X (e.g. $1, $2, etc) of lines which match # the pattern following this directive will be summed and reported # using the given report message; $s is bound to the sum, and $n is # bound to the number of matching lines when the report message is # evaluated # # Remember that pattern lines are Perl regular expressions. In # particular remember to escape the special characters $^()[]+* or you # won't get the effect you want. # check our args require 'getopts.pl'; $usage = "usage: $0 template [logfile]"; &Getopts( 'd' ) || die "$usage\n"; $#ARGV >= 0 || die "$usage\n"; # init $state = 0; $ignore = 0; $ignored = 0; @count = (); $reports = ""; $unknown = ""; # read the template open( TEMPLATE, "<".shift ) || die "fatal: cannot read template\n"; while( $line =