Last active
December 28, 2015 05:49
-
-
Save waffle2k/7452247 to your computer and use it in GitHub Desktop.
(zabbix-package-versions ; ssh zabbix02 zabbix-package-versions) | compare-packages.pl
This file contains hidden or 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; | |
| sub map_set { | |
| my $fn = shift; | |
| die unless -f $fn; | |
| my $map = {}; | |
| open my $fd, "<$fn"; | |
| my $text = do { | |
| local $/; | |
| <$fd>; | |
| }; | |
| for( split( /\n/, $text ) ){ | |
| if( /^(\S+)\s+(\S+)/ ){ | |
| $map->{"$1"} = $2; | |
| } | |
| } | |
| return $map; | |
| } | |
| sub map_combined { | |
| my $text = shift; | |
| my $megamap = {}; | |
| for( split( /\n/, $text ) ){ | |
| if( /^(\S+)\s+(\S+)\s+(\S+)/ ){ | |
| $megamap->{"$1"}->{"$2"} = $3; | |
| } | |
| } | |
| die "Cannot parse more than two maps" | |
| if( scalar keys %$megamap != 2 ); | |
| my @k = keys %$megamap; | |
| return( $megamap->{$k[0]}, $k[0], $megamap->{$k[1]}, $k[1] ); | |
| } | |
| my ( $set1fn, $set2fn ) = @ARGV; | |
| my $map1 = {}; | |
| my $map2 = {}; | |
| unless( -e $set1fn and -e $set2fn ){ | |
| my $text = do { local $/; <STDIN>; }; | |
| ( $map1, $set1fn, $map2, $set2fn ) = map_combined( $text ); | |
| } else { | |
| $map1 = map_set( $set1fn ); | |
| $map2 = map_set( $set2fn ); | |
| } | |
| for my $key ( keys %$map2 ){ | |
| unless( defined $map1->{"$key"} ){ | |
| print "[E] $key not defined in $set1fn\n"; | |
| } | |
| } | |
| for my $key ( keys %$map1 ){ | |
| unless( defined $map2->{"$key"} ){ | |
| print "[E] $key not defined in $set2fn\n"; | |
| next; | |
| } | |
| unless( $map2->{"$key"} eq $map1->{"$key"} ){ | |
| print "[W] version missmatch [$key] {" . $set1fn . "}[" . $map1->{"$key"} . "] {" . $set2fn . "}[" . $map2->{"$key"} . "]\n"; | |
| } | |
| } |
This file contains hidden or 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
| #!/bin/bash | |
| /usr/bin/dpkg -l '*zabbix*' '*postgres*' | /usr/bin/awk '/^ii /{printf "%s\t\t%s\n",$2,$3}' | | |
| while read LINE | |
| do | |
| echo "$(hostname) $LINE" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment