digcomp.pl revision 247bf378605811d695e968dbe930a7fc45c0038e
#
;
;
# $Id: digcomp.pl,v 1.14 2007/06/19 23:47:00 tbox Exp $
# Compare two files, each with the output from dig, for differences.
# Ignore "unimportant" differences, like ordering of NS lines, TTL's,
# etc...
$count = 0;
$firstname = "";
$status = 0;
$rcode1 = "none";
$rcode2 = "none";
while (<FILE1>) {
chomp;
if (/^;.+status:\s+(\S+).+$/) {
$rcode1 = $1;
}
next if (/^;/);
if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
$name = $1;
$class = $2;
$type = $3;
$value = $4;
if ($type eq "SOA") {
$name = "$name$count";
$count++;
}
}
print("Duplicate entry in $file1:\n> $_\n< $line\n");
} else {
$entry{"$name ; $class.$type ; $value"} = $_;
}
}
}
close(FILE1);
$printed = 0;
while (<FILE2>) {
chomp;
if (/^;.+status:\s+(\S+).+$/) {
$rcode2 = $1;
}
next if (/^;/);
if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
$name = $1;
$class = $2;
$type = $3;
$value = $4;
$count--;
$name = "$name$count";
}
} else {
print("Only in $file2 (missing from $file1):\n")
if ($printed == 0);
print("> $_\n");
$printed++;
$status = 1;
}
}
}
close(FILE2);
$printed = 0;
print("Only in $file1 (missing from $file2):\n")
if ($printed == 0);
print("< $entry{$key}\n");
$status = 1;
$printed++;
}
}
print("< status: $rcode1\n");
print("> status: $rcode2\n");
$status = 1;
}
exit($status);