Created
April 27, 2020 23:52
-
-
Save ilyaevseev/04d66b7c608fff87c68d6adfd3492a81 to your computer and use it in GitHub Desktop.
Compare two sysctl outputs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
die "Usage: $0 sysctl1.lst sysctl2.lst\n" if @ARGV != 2; | |
sub file2list($) { | |
my $fname = shift; | |
open F, $fname or die "Cannot open $fname: $!\n"; | |
my @lines = <F>; | |
close F; | |
chomp @lines; | |
my %k = map { my ($a,$b) = split / = /, $_; $a => $b } @lines; | |
\%k | |
} | |
my $a = file2list($ARGV[0]); | |
my $b = file2list($ARGV[1]); | |
my (%onlya, %onlyb, %mismatch); | |
while (my ($k,$v) = each %$a) { | |
if (!exists($b->{$k})) { | |
$onlya{$k} = $v | |
} elsif ($b->{$k} ne $v) { | |
$mismatch{$k} = "$v == $b->{$k}" | |
} | |
} | |
while (my ($k,$v) = each %$b) { | |
$onlyb{$k} = $v if !exists($a->{$k}); | |
} | |
sub print_list($$) { | |
my ($title, $listref) = @_; | |
print "\n==== $title ====\n"; | |
printf("%-40s %s\n", $_, $listref->{$_}) foreach sort keys %$listref; | |
} | |
print_list "MISMATSH", \%mismatch; | |
print_list "ONLY AAA", \%onlya; | |
print_list "ONLY BBB", \%onlyb; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment