#!/usr/bin/perl -w # Get ClearCase license usage, v1.1 # Ed Finch (efinch@eos.hitc.com) September 1997 # Run /usr/atria/bin/clearlicense. Save the current time (in seconds), # the maximum and current license usage for ClearCase, MultiSite and # Attache to a file. use File::Basename; use Getopt::Long; use strict; # Variables set by Getopt use vars '$opt_long'; # store license information in long format my($me); # basename(1) of this script my($now); # time the script was run my($license_file); # where to write the usage information my($max_clearcase_licenses); # maximum ClearCase licenses my($clearcase_licenses_used); # ClearCase licenses in use my($max_multisite_licenses); # maximum MultiSite licenses my($multisite_licenses_used); # MultiSite licenses in use my($max_attache_licenses); # maximum Attache licenses my($attache_licenses_used); # Attache licenses in use $me = basename($0); # We must have some arguments if (scalar @ARGV == 0) { &Usage; } # Process command-line parameters GetOptions("long|l") or die "$me: bad options\n"; # There should be 1 argument, the filename if (scalar @ARGV != 1) { print "Bad arguments\n"; &Usage; } $license_file = shift (@ARGV); if (! defined $license_file) { print "A file license sample file must be specified\n"; &Usage; } # Initialize these so they will have _some_ value $max_clearcase_licenses = 0; $clearcase_licenses_used = 0; $max_multisite_licenses = 0; $multisite_licenses_used = 0; $max_attache_licenses = 0; $attache_licenses_used = 0; # Get ClearCase license usage open CLEARLICENSE, "/usr/atria/bin/clearlicense -product ClearCase 2>/dev/null |" or die "Can't run clearlicense: $!\n"; while () { if ($_ =~ /Maximum active users allowed: (\d+)/) { $max_clearcase_licenses = $1; } elsif ($_ =~ /Current active users: (\d+)/) { $clearcase_licenses_used = $1; } } close CLEARLICENSE; # Get MultiSite license usage open CLEARLICENSE, "/usr/atria/bin/clearlicense -product MultiSite 2>/dev/null |" or die "Can't run clearlicense: $!\n"; while () { if ($_ =~ /Maximum active users allowed: (\d+)/) { $max_multisite_licenses = $1; } elsif ($_ =~ /Current active users: (\d+)/) { $multisite_licenses_used = $1; } } close CLEARLICENSE; # Get Attache license usage open CLEARLICENSE, "/usr/atria/bin/clearlicense -product Attache 2>/dev/null |" or die "Can't run clearlicense: $!\n"; while () { if ($_ =~ /Maximum active users allowed: (\d+)/) { $max_attache_licenses = $1; } elsif ($_ =~ /Current active users: (\d+)/) { $attache_licenses_used = $1; } } close CLEARLICENSE; # Append to the file containing the license samples open SAMPLES, ">> $license_file" or die "Can't open $license_file: $!\n"; $now=time; print SAMPLES $now . " " . $max_clearcase_licenses . " " . $clearcase_licenses_used . " " . $max_multisite_licenses . " " . $multisite_licenses_used . " " . $max_attache_licenses . " " . $attache_licenses_used; if ($opt_long) { print SAMPLES " " . localtime($now) . "\n"; } else { print SAMPLES "\n"; } close SAMPLES; # All done exit 0; sub Usage() { print <<"EOF"; Usage: $me [-l] file -l License samples are normally written in short format, which looks like "873940654 205 3 0 0 0 0". This option causes the first field, seconds since the epoch, to be expanded via localtime(). The sample is then written as "873940661 205 3 0 0 0 0 Wed Sep 10 21:17:41 1997". file The file where license information is written EOF exit; }