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
|
#!/usr/bin/perl
use strict;
use warnings;
use SiteSummary;
use Getopt::Std;
my %agegroup =
(
0 => '>0 days',
3 => '>3 days',
7 => '>one week',
14 => '>14 days',
30 => '>30 days',
90 => '>90 days',
180 => '>180 days',
);
my %agedist;
my %opts;
sub usage {
my $retval = shift;
print <<EOF;
Usage: $0 [-l]
-l list hosts with the given age
EOF
exit $retval;
}
getopt("l", \%opts) || usage(1);
for_all_hosts(\&handle_host);
print_summary();
sub handle_host {
my $hostid = shift;
my $topdir = get_filepath_current($hostid, "/");
my $age = (time() - (stat($topdir))[9]) / (60 * 60 * 24);
my $thisgroup;
for my $group (sort { $a <=> $b; } keys %agegroup) {
if ($age > $group) {
$thisgroup = $group;
}
}
if (defined $thisgroup) {
if (exists $agedist{$thisgroup}) {
push @{$agedist{$thisgroup}}, $hostid ;
} else {
$agedist{$thisgroup} = [$hostid];
}
}
}
sub print_summary {
printf(" %-20s %5s\n", "age", "count");
for my $group (sort { $a <=> $b; } keys %agedist) {
printf(" %-20s %5d\n", $agegroup{$group}, scalar @{$agedist{$group}});
if (exists $opts{l}) {
for my $hostid (sort @{$agedist{$group}}) {
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;
}
print "\n";
}
}
}
|