#!/usr/bin/perl -w # # submit-license-audit.pl -- Audit all the rush license file Valid: dates # # Name Vers Date Comments # Greg Ercolano 1.00 08/06/08 - Initial implementation (submit-audit.pl) # Greg Ercolano 1.10 09/23/13 - Modified to audit rush license.dat files # # (C) Copyright 2008 Seriss Corporation. All Rights Reserved. # Do not remove this header or copyright notice. You may use and change # this software for internal use, but may not re-distribute it. # If you make changes, please add your name/version/date to the list # above using the format shown. # use strict; $|=1; umask(0); ### MODIFIABLE VARIABLES: START #### # Use forward slashes in pathnames $G::logdir = "//eagle/net/tmp/logs"; # where to write rush error logs $G::cpus = '+any=10.1@1'; # cpus to be audited ### MODIFIABLE VARIABLES: END #### $G::audit_file = "$G::logdir/rush-license-audit.txt"; # audit log file @G::search = ( "Licenses:", "Valid:", "Version:" ); # SUBMIT if ( ! defined($ARGV[0]) ) { $G::self = $0; $G::self =~ s%\\%/%g; # \\foo\bar -> //foo/bar # PREVENT 'NETWORK WORM' STYLE RECURSION if ( defined($ENV{RUSH_ISDAEMON}) ) { exit(1); } # CREATE LOGDIR if ( ! -d $G::logdir ) { unless(mkdir($G::logdir, 0777)) { print STDERR "mkdir $G::logdir: $!\n"; exit(1); } } # CREATE EMPTY AUDIT FILE unless(open(AUDIT, ">$G::audit_file")) { print STDERR "ERROR: $G::audit_file: $!\n"; exit(1); } print AUDIT "*** RUSH LICENSE AUDIT ***\n\n"; # CREATE COLUMN HEADINGS print AUDIT sprintf("%-22s ", "Hostname"); foreach my $search ( @G::search ) { print AUDIT sprintf("%-22s ", $search); } print AUDIT "\n"; # DOTTED LINE HEADING print AUDIT sprintf("%-22s ", ("-"x22)); foreach my $search ( @G::search ) { print AUDIT sprintf("%-22s ", ("-"x22)); } print AUDIT "\n"; close(AUDIT); # SUBMIT JOB unless( open(SUBMIT, "|rush -submit") ) { print STDERR "rush -submit: $!\n"; exit(1); } print SUBMIT <<"EOF"; title RUSH_LICENSE_AUDIT ram 1 frames 1-1000 logdir $G::logdir command perl $G::self -render cpus $G::cpus imgcommand perl $G::self -imgcommand EOF close(SUBMIT); # Non-zero exit indicates submit failed if ( $? >> 8 ) { print STDERR "--- Submit failed\n"; exit(1); } # Submit Failed exit(0); # Submit OK } # RETURN THE REQUESTED LICENSE INFO # $1 - string to search for # sub GetLicenseInfo($) { my $search = $_[0]; my $licfile = ""; if ( -e "c:/rush/etc/license.dat" ) { $licfile = "c:/rush/etc/license.dat"; } else { $licfile = "/usr/local/rush/etc/license.dat"; } unless(open(LIC,"<$licfile")) { print "ERROR: can't open $licfile: $!\n"; exit(1); } my $out = ""; while () { if ( /$search/ ) { $out = $_; $out =~ s/.*${search}[ ]*//g; } } close(LIC); $out =~ s/^#[ ]*//; $out =~ s/[\r\n]*//g; chomp($out); return($out); } # RUNNING ON REMOTE MACHINE? if ( $ARGV[0] eq "-render" ) { print "--- Working on frame host $ENV{RUSH_HOSTNAME}\n"; # REMOVE THIS HOST FROM JOB (SO IT DOESN'T RUN AGAIN) system("rush -an $ENV{RUSH_HOSTNAME} -fu"); # BUILD AN AUDIT LINE FOR THIS MACHINE my $out = sprintf("%-22.22s ", $ENV{RUSH_HOSTNAME}); foreach my $search ( @G::search ) { $out .= sprintf("%-22s ", GetLicenseInfo($search)); } $out .= "\n"; # APPEND LINE TO AUDIT FILE WITH SINGLE "ATOMIC WRITE" print "Appending to ${G::audit_file}: $out"; unless(open(AUDIT, ">>$G::audit_file")) { print STDERR "ERROR: $G::audit_file: $!\n"; exit(1); } else { syswrite(AUDIT, $out, length($out)); close(AUDIT); } print "\n--- DONE\n"; exit(0); } # USER MIDDLE CLICKED ON A FRAME IN IRUSH? (IMGCOMMAND) if ( $ARGV[0] eq "-imgcommand" ) { my $cmd; if ( -d "c:/rush/etc" ) { # WINDOWS $ENV{PATH} = "c:/program files/windows nt/accessories:$ENV{PATH}"; $G::audit_file =~ s%/%\\%g; $cmd = "start wordpad $G::audit_file"; } elsif ( -d "/Applications" ) { # MAC $cmd = "open $G::audit_file"; } else { # LINUX $cmd = "gvim $G::audit_file"; $cmd =~ s%\\%/%g; } system($cmd); exit(0); }