#!/usr/bin/perl # # Fix the logwatch patterns to get rid of annoying multiple messages # that really should be merged. use File::Compare; use File::Copy; # Step 1 - find the dovecot script file location from the # logwatch package file list. # my $fh; my $infile; open($fh, '-|', '/bin/rpm', '-q', '--list', 'logwatch'); while (<$fh>) { if (/\/dovecot$/) { chomp; $infile=$_; last; } } close($fh); undef $fh; # # Step 2 - copy file to temp, looking for first "while" statement and # adding a "next if" to skip all lines that look like the annoying # dovecot.*stored mail into mailbox messages I never want to see. # my $outfile = "/tmp/dovecot$$"; my $outf; open($fh, '<', $infile) || die "Cannot read $infile : $!\n"; open($outf, '>', $outfile) || die "Cannot write $outfile : $!\n"; my $found=0; while (<$fh>) { if (/^\s*while.*ThisLine.*$/) { $found=1; last; } else { print $outf $_; } } if (! $found) { close($outf); unlink($outfile); die "Did not find while ... ThisLine definition!\n"; } print $outf $_; print $outf ' next if ($ThisLine =~ /^.*dovecot.*stored mail into mailbox.*$/);', "\n"; while (<$fh>) { next if (/^.*next if.*dovecot.*stored mail into mailbox.*$/); print $outf $_; } close($fh); close($outf); if (compare($infile, $outfile) != 0) { # Looks like the files are different, I really need to fix the # function. Copy the outfile back over the top of the infile. print "Updating $infile\n"; copy($outfile, $infile); } unlink($outfile); # Repeat the same thing on the named script... # Step 1 - find the named script file location from the # logwatch package file list. # undef $fh; undef $infile; open($fh, '-|', '/bin/rpm', '-q', '--list', 'logwatch'); while (<$fh>) { if (/\/named$/) { chomp; $infile=$_; last; } } close($fh); undef $fh; # # Step 2 - copy file to temp, looking for first "while" statement and # adding a "next if" to skip all lines that look like the annoying # DNS lookup errors I never want to see. # $outfile = "/tmp/named$$"; undef $outf; open($fh, '<', $infile) || die "Cannot read $infile : $!\n"; open($outf, '>', $outfile) || die "Cannot write $outfile : $!\n"; $found=0; while (<$fh>) { if (/^\s*while.*ThisLine.*$/) { $found=1; last; } else { print $outf $_; } } if (! $found) { close($outf); unlink($outfile); die "Did not find while ... ThisLine definition!\n"; } print $outf $_; print $outf ' next if ($ThisLine =~ /^.*DNS format error from.*$/);', "\n"; print $outf ' next if ($ThisLine =~ /^.*error.*FORMERR.*resolving.*$/);', "\n"; while (<$fh>) { next if (/^.*next if.*DNS format error from.*$/); next if (/^.*next if.*error.*FORMERR.*resolving.*$/); print $outf $_; } close($fh); close($outf); if (compare($infile, $outfile) != 0) { # Looks like the files are different, I really need to fix the # function. Copy the outfile back over the top of the infile. print "Updating $infile\n"; copy($outfile, $infile); } unlink($outfile);