Improved "compare-lpps" script ...



I've made a few improvements to the compare-lpps script that I posted to the list last week:

* If a fileset is installed and at the same version on all of the systems, an equal sign will be printed at the end of its line.

* The script now takes an argument of "--diff". When used, the report will only contain those filesets that are either not installed on all systems, or are at differing versions.

Hope this is useful for someone.

-- Sandy

#######################################################################

#!/usr/bin/perl -w
#$Id: compare-lpps,v 1.3 2006/04/11 04:31:50 ssklar Exp ssklar $

=head1 NAME

compare-lpps - compares and reports on the installed LPPs on multiple AIX systems

=head1 SYNOPSIS

B<compare-lpps> I<[ --diff ]> I<file1> I<file2> ... I<[ fileN ]>

=head1 DESCRIPTION

B<compare-lpps> parses the output of the "lslpp" command from two or more AIX systems and generates a tabular report, detailing the version of each LPP (Licensed Program Product) on each system in an easy to compare format. If the "--diff" flag is used, LPPs that are the same on all hosts are omitted from the report.

=head1 USAGE

Before using this program, the user will need to run the "lslpp -Lc" command on each system to be included in the report. The output of the above command should be saved to a file whose name is that of the system it was run on.

For example, if you have three AIX systems, named "buffy", "kendra", and "faith", you could generate these files by running:

$ for host in buffy kendra faith; do \
> ssh $host lslpp -Lc > $host \
> done

Once those files are saved, you can then generate the report by running:

$ compare-lpps buffy kendra faith

The report will be written to STDOUT, and can be imported as a space- delimited file into Excel, if desired. The output will be similar to ...

LPP buffy faith kendra
----------------------------- ------------- ------------- ------------- ---
AIX-rpm-5.2.0.10-1 5.2.0.10 - 5.2.0.10
CLArrayS3 5.1.0.6 - -
EMC.CLARiiON.fcp.rte - 5.2.0.1 5.2.0.1
EMCpower.base 4.4.2.0 4.4.2.0 4.4.2.0 =
EMCpower.consistency_grp 4.4.2.0 4.4.2.0 4.4.2.0 =
EMCpower.hr 4.4.2.0 4.4.2.0 4.4.2.0 =

... and so on. If a fileset is installed on all of the systems, and it is at the same VRMF on all of the systems, the that LPP's line will be printed with an equal sign ("=") at the end. If the I<-- diff> argument is provided, the report will not include those LPPs that are installed and are at the same version (VRMF) on all of the systems.

=head1 AUTHOR

B<compare-lpps> was writen by Sandor W. Sklar <ssklar@xxxxxxxxxxxx>.
<http://www.stanford.edu/~ssklar/compare-lpps>

=head1 COPYRIGHT AND LICENSE

Copyright 2006 Board of Trustees, Leland Stanford Jr. University.

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

=head1 VERSION

$Revision: 1.3 $
$Date: 2006/04/11 04:31:50 $

=cut

use strict;
use File::Basename;

my ($type, @hosts, %all_lpps, %lpps);

unless (scalar (@ARGV) > 1) {

print "Usage: compare_lpps [ --diff ] host1 host2 [ ... hostN ]\n";
exit 1

};

if ($ARGV[0] =~ /-dif/) {

$type = "diff";
shift

} else {

$type = "full";

};

foreach (@ARGV) {

my $host = basename($_);

push (@hosts, $host);

open (FILE, "$_") or
die "Couldn't read file $_: $!";

while (<FILE>) {

next if /^#/;

my @fields = split (/:/, $_);

$all_lpps{$fields[1]} = $fields[7];

$lpps{$host}{$fields[1]} = $fields[2];

};

close FILE;

};

printf ("%-40s", "LPP");

for (0 .. $#hosts) {

printf ("%-14s", $hosts[$_]);

};

print "\n";

print "-" x 39 . " ";

for (0 .. $#hosts) {

print "-" x 13 . " ";

};

print "---\n";

my (@same, @diff);


foreach my $lpp (sort keys %all_lpps) {

my $line = sprintf ("%-40s", "$lpp");

my @version;

foreach my $host (@hosts) {

if (exists $lpps{$host}{$lpp}) {

push (@version, $lpps{$host}{$lpp});

$line .= sprintf ("%-14s", $lpps{$host}{$lpp});

} else {

push (@version, "-");

$line .= sprintf ("%-14s", "-");

};

};

if ( ! grep $_ ne $version[0], @version ) {

push (@same, "$line" . " =\n");

} else {

push (@diff, "$line \n");
};

};

if ($type eq "diff") {

print @diff;

} else {

print sort (@same, @diff);

};


exit 0;

#######################################################################