#!/usr/bin/perl # ------------------------------------------------------------------- # # compare-access-files.pl - Spot duplicates in sendmail access files. # # This script compares one access control file for sendmail to another # sendmail access control file. Duplicates will be printed and you # be prompted to comment them out of the compared file. # # ses0s, Wed Mar 17 14:47:22 PST 2004 # ------------------------------------------------------------------- # my $TMP_new_file = "/tmp/$0.out"; # ------------------------------------------------------------------- # # You probably don't need to edit stuff below here. # ------------------------------------------------------------------- # my %seenIt; my ($master_file, $compare_file) = (shift, shift); (-f $compare_file and -f ($master_file)) or die "Usage: $0 masterFile compareFile\n"; open MASTER, "<$master_file" or die; while () { /^([a-z0-9\-\.]{1,122}\.[a-z]{2,4})(\s+.*)$/ or die "Tripped on $_"; die "Duplicate found in master file! Remove $1\n" if $seenIt{$1} == 1; $seenIt{$1} = 1; } close MASTER; open O, ">$TMP_new_file" or die; my $count = 0; open COMPARE, "<$compare_file" or die; while () { if (/^([a-z0-9\-\.]{1,122}\.[a-z]{2,4})(\s+.*)$/) { print O "# JW # " if $seenIt{$1} == 1; print "Found $1\n" if $seenIt{$1} == 1; $count++ if $seenIt{$1} == 1;; } print O; } close COMPARE; close O; if ($count > 0) { $| = 666; my $s = 's'; undef $s if $count == 1; print "$count duplicate${s} found. Comment out dups from ${compare_file}? [yN]"; my $ask = ; $ask =~ /^y/i and (rename $TMP_new_file, $compare_file) and (print "Done\n"); } else { print "No duplicates found.\n"; unlink $TMP_new_file; }