#!/usr/bin/perl -w use strict; use Getopt::Long; my $full = 0; my $debug = 0; my $header = 0; GetOptions('full' => \$full, debug =>\$debug, header => \$header); my $sudo = ''; $sudo = "sudo " if ($> != 0); my ($host, @hosts, $line, @lines, $master, $key); my ($expstring, $expstate, $expdate, $time_left); chomp(@hosts = qx{$sudo /usr/openv/netbackup/bin/admincmd/bpstulist | awk '{ print \$3 }' | sort -u}); chomp($master = qx{$sudo /usr/openv/volmgr/bin/vmglob -get_gdbhost}); print STDOUT "hostname,NetBackup master,license key,status,expiration date\n" if $header; foreach $host (@hosts) { print STDERR "Querying $host ... " if $debug; chomp(@lines = qx{$sudo /usr/openv/netbackup/bin/admincmd/bpminlicense -M $host -verbose}); print STDERR "got response." if $debug; undef $key; undef $expstring; undef $time_left; foreach $line (@lines) { if ($line =~ m/^[A-Z0-9]/) { if (defined($key) && ($full || $debug || defined($expstring))) { if ($debug) { print STDERR "\n $key", (defined($expstring)) ? " $expstring" : " does not expire"; print STDERR " ($time_left) " if defined($time_left); } if ($full || defined($expstring)) { print STDOUT "$host,$master,$key,", (defined($expstate)) ? $expstate : "permanent", ",", (defined($expdate)) ? $expdate : "never", "\n"; } undef $key; undef $time_left; undef $expstring; undef $expstate; undef $expdate; } $key = (split(' ', $line))[0]; } elsif ($line =~ m/^ Expiration/) { $expstring = $line; $expstring =~ s,^ Expiration = ,,; $expstring =~ s,Expired,EXPIRED on,; $expstring =~ s,Not expired,expires on,; $expstate = substr($expstring, 0, 7); $expdate = substr($expstring, 11); } elsif ($line =~ m/^ Time Left/) { $time_left = $line; $time_left =~ s, Time Left = ,,; } # XXX Features? Temp keys just have them all, no way to check # what we're using, really... } if ($debug) { print STDERR "\n $key", (defined($expstring)) ? " $expstring" : " does not expire"; print STDERR " ($time_left)" if defined($time_left); } if ($full || defined($expstring)) { print STDOUT "$host,$master,$key,", (defined($expstate)) ? $expstate : "permanent", ",", (defined($expdate)) ? $expdate : "never", "\n"; } undef $key; undef $time_left; undef $expstring; undef $expstate; undef $expdate; print STDERR "\n" if $debug; }