File: kernelversion-summary

package info (click to toggle)
sitesummary 0.1.17+deb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 468 kB
  • ctags: 103
  • sloc: perl: 1,742; sh: 787; makefile: 84
file content (53 lines) | stat: -rwxr-xr-x 1,216 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl

use strict;
use warnings;

use SiteSummary;
use Getopt::Std;

my %kernelvers;
my %opts;

sub usage {
    my $retval = shift;
    print <<EOF;
Usage: $0 [-l]
   -l   list hosts using the given kernel versions
EOF
    exit $retval;
}

getopt("l", \%opts) || usage(1);

for_all_hosts(\&handle_host);

print_summary();

sub handle_host {
    my $hostid = shift;
    #print "$hostid\n";
    for my $kver (get_linux_kernel_ver($hostid)) {
        $kver = "" unless defined $kver;
        if (exists $kernelvers{$kver}) {
            push @{$kernelvers{$kver}}, $hostid ;
        } else {
            $kernelvers{$kver} = [$hostid];
        }
    }
}

sub print_summary {
    printf("  %-20s %5s\n", "kernel", "count");
    for my $kver (sort keys %kernelvers) {
        printf("  %-20s %5d\n", $kver,  scalar @{$kernelvers{$kver}});
        if (exists $opts{l}) {
            for my $hostid (sort @{$kernelvers{$kver}}) {
                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;
            }
        }
    }
}