[b0b0b6]: chk_dups Maximize Restore History

Download this file

chk_dups    55 lines (43 with data), 1.3 kB

#!/usr/bin/perl -w
# chkdups - look for duplicate mibs files.

my $file = shift || 'mib_index.txt';
$diff    = shift ||  0;
die "Usage: $0 mib_index.txt\n" unless -r $file;

open (FILE,"<$file") or die "can't open file : $file. $!\n";

$dir = '';
while (<FILE>){
    chomp;
    if ($_ =~ /^\.\/(.*)\/\.index/){ 
        $dir = "$1/";    
    }
    elsif ($_ =~ /^(.*)\s+(.*)$/){
        my $mib = $1; my $file = $2;
        push @{$MIBS{$mib}},"$dir$file";
    }
}

foreach my $mib (keys %MIBS){
    next unless scalar(@{$MIBS{$mib}} > 1);
    print "Duplicate $mib\n";
    if ($diff) {
        my $diff_cmd = "diff -bB $MIBS{$mib}->[0] $MIBS{$mib}->[1]";
        my $diff = `$diff_cmd`;
        if ($diff !~ /^\s*$/){
            print "$diff_cmd\n";
            $diff =~ s/^/    /gm;
            print $diff;
        }
    }

    my $mib0  = `grep -i last-updated $MIBS{$mib}->[0]`;
    my $mib1  = `grep -i last-updated $MIBS{$mib}->[1]`;
    
    chomp($mib0);
    chomp($mib1);

    $mib0 =~ s/^\s*//;
    $mib1 =~ s/^\s*//;

    $mib0 =~ s/--.*//;
    $mib1 =~ s/--.*//;

    $mib0 =~ s/\s+/ /;
    $mib1 =~ s/\s+/ /;

    printf "  %-50s %s\n", $MIBS{$mib}->[0] , $mib0;
    printf "  %-50s %s\n", $MIBS{$mib}->[1] , $mib1;

    print  "  vimdiff $MIBS{$mib}->[0] $MIBS{$mib}->[1]\n";
}