-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack-scan.pl
executable file
·123 lines (98 loc) · 2.42 KB
/
pack-scan.pl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/perl
use POSIX;
if (not @ARGV || @ARGV != 2) {
print "Usage: ./pack-info.pl [USER HOST]\n";
print "$ARGV[0]\n";
exit(1);
}
if (@ARGV == 2) {
our $ssh = 1;
$host = $ARGV[1];
$user = $ARGV[0];
}
if (not @ARGV) {
our $ssh = 0;
$host=`hostname`;
}
$release =&run_com('cat /etc/redhat-release');
chomp($release);
chomp($host);
$output = &run_com('rpm -qa --qf "%{NAME}|%{VERSION}|%{RELEASE}|%{INSTALLTIME}|%{VENDOR}|%{BUILDTIME}|%{BUILDHOST}|%{SOURCERPM}|%{LICENSE}|%{PACKAGER}\n"');
@lines = split(/\n/, $output);
@greatest = []; #install time
@greatest_build = [];
$rhcount = 0;
for($i = 0; $i < @lines; $i++) {
@cols = split(/\|/, $lines[$i]);
if (index($cols[6], 'redhat.com') > -1 and
index($cols[6], 'fedora') == -1 and
index($cols[6], 'rhndev') == -1) {
$rhcount++;
if ($greatest == -1) {
@greatest = @cols;
}
elsif( $greatest[3] < $cols[3]) {
@greatest = @cols;
}
if ($greatest_build == -1) {
@greatest_build = @cols;
}
elsif( $greatest_build[5] < $cols[5]) {
@greatest_build = @cols;
}
}
}
$result = "";
$curr_date = `date +%s`;
chomp($curr_date);
$result = "$host ($release) - ".$curr_date;
if ($rhcount != 0) {
$result = $result."\nRed Hat (Y/N): Y\n";
$result = $result."RH Pkgs: $rhcount/".scalar @lines;
$result = $result."\nLast Installed: ";
$result = $result.details_install(@greatest);
$result = $result."\nLast Built: ";
$result = $result.details_built(@greatest_build);
}
else {
$result = $result."\nRed Hat (Y/N): N\n";
}
save_results($result, $host);
exit;
sub details_install {
@cols = @_;
$tmp = $cols[0]."-".$cols[1]."-".$cols[2];
$tmp = $tmp." Installed: ";
$time = localtime($cols[3] + 0);
$tmp = $tmp."$time";
return $tmp;
}
sub details_built {
@cols = @_;
$tmp = $cols[0]."-".$cols[1]."-".$cols[2];
$time_build = localtime($cols[5] + 0);
$tmp = $tmp." Built: ".$time_build;
return $tmp;
}
sub save_results {
$output = $_[0];
$host = $_[1];
open FILE, ">>", "$host.txt" or print "ERROR, cannot write file";
print FILE $output;
close FILE;
`zip $host.zip $host.txt`;
`rm $host.txt`;
if(!$ssm) {
print "Please submit $host.zip\n";
}
}
sub run_com {
$com = $_[0];
if ($ssh) {
$com = "ssh ".$user."@".$host." '".$com."'";
return `$com`;
}
else {
return `$com`;
}
}