1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#!/usr/bin/perl
use strict;
use warnings;
use SiteSummary;
use Getopt::Long;
my %pkgvers;
my $listhosts;
sub usage {
my $retval = shift;
print <<EOF;
Usage: $0 <packagename> [-l]
-l list hosts using the given kernel versions
EOF
exit $retval;
}
GetOptions("l", \$listhosts) || usage(1);
my $pkg = $ARGV[0];
unless ($pkg) {
print <<EOF;
Error: missing name of package to look for.
EOF
usage(1);
}
for_all_hosts(\&handle_host);
print_summary();
sub get_pkg_ver {
my $pkg = shift;
my $hostid = shift;
my $path = get_filepath_current($hostid, "/debian/dpkg-l");
my $pver = undef;
if (open (FILE, $path)) {
while(<FILE>) {
chomp;
next unless (/^ii\s.+$/);
my @f = (split(/\s+/, $_));
if ( ($f[1] =~ m/^(.+):.+$/ && $pkg eq $1)
|| ($pkg eq $f[1]) ) {
$pver = $f[2];
}
}
close(FILE);
return $pver;
} else {
return undef;
}
}
sub handle_host {
my $hostid = shift;
#print "$hostid\n";
for my $pver (get_pkg_ver($pkg, $hostid)) {
$pver = "<missing>" unless defined $pver;
if (exists $pkgvers{$pver}) {
push @{$pkgvers{$pver}}, $hostid ;
} else {
$pkgvers{$pver} = [$hostid];
}
}
}
sub print_summary {
printf(" %-20s %5s\n", "$pkg version", "count");
for my $pver (sort keys %pkgvers) {
printf(" %-20s %5d\n", $pver, scalar @{$pkgvers{$pver}});
if ($listhosts) {
for my $hostid (sort @{$pkgvers{$pver}}) {
my $hostname = get_hostname($hostid);
my $site = get_site($hostid) || "";
my $sitegroup = get_sitegroup($hostid) || "";
printf " %s %s/%s %s\n", $hostname, $site, $sitegroup, $hostid;
}
}
}
}
|