diff -r 000000000000 -r 83f4b4db085c bldsystemtools/commonbldutils/AntiVirus.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bldsystemtools/commonbldutils/AntiVirus.pl Tue Feb 02 01:39:43 2010 +0200 @@ -0,0 +1,144 @@ +#!/usr/bin/perl -w +use strict; +use FindBin; # for FindBin::Bin +use lib $FindBin::Bin; # for BldMachineDir (if in same dir. as this .PL file) +use Getopt::Long; # Get long options +use AntiVirus qw{Start Stop Scan WaitTillAntiVirusStarts}; + +####my $gTimeNow = time(); + +# Get the command line args +my ($gCommand,$gOutFilesDir ,$gDirsToScan,$gWaitingTime, $gRetries) = &ProcessCommandLine(); + +# If the command is to stop the services/processes, then do so. + +if($gCommand eq 'STOP') +{ + Stop($gWaitingTime, $gRetries); +} +elsif($gCommand eq 'START') +{ + Start(); +} +else # ($gCommand eq 'SCAN') NB Any unknown command has been caught by ProcessCommandLine() +{ + Scan($gOutFilesDir, $gDirsToScan); +} + +####printf ("DEBUG MSG: Elapsed time = %d seconds", time() - $gTimeNow); ####???? For debugging! + +################################################################################ +# ProcessCommandLine # +# Inputs: None (Gets data from @ARGV) # +# Outputs: ($iCommand, $iOutFilesDir, \@iDirsToScan) # +# Remarks: None # +################################################################################ +sub ProcessCommandLine +{ + my ($iHelp, $iCommand,$iOutFilesDir,@iDirsToScan,$iWaitingTime, $iRetries ); + unless (GetOptions('h' => \$iHelp, 'o=s' => \$iOutFilesDir, 'c=s' => \$iCommand,'w=s' => \$iWaitingTime,'r=s' => \$iRetries, 'd=s' => \@iDirsToScan)) + { + Usage('Command Line error(s), as above.'); + } + if (scalar @ARGV) + { + Usage("Redundant data on Command Line: @ARGV"); + } + if ($iHelp) + { + Usage(); + } + unless(defined($iCommand)) + { + Usage('No command given'); + } + # Uppercase $iCommand once and for all. Then we can check using 'eq'. + # NB: uppercasing undef results in a defined, but empty, string! + $iCommand = uc $iCommand; + + + + if($iCommand eq 'SCAN') + { + unless((scalar @iDirsToScan) and ($iOutFilesDir)) + { # Make sure there are some directories to scan! + # It is an error to ask for a scan and to not + # supply directories, so print usage information + Usage('With SCAN command, must specify directory(ies) and output file'); + } + return ($iCommand, $iOutFilesDir, \@iDirsToScan); + } + + if(($iCommand eq 'START')or ($iCommand eq 'STOP')) + { + if((scalar @iDirsToScan) or ($iOutFilesDir)) + { # Can't specify directories when starting and stopping + # the AV processes and services. + Usage('With START/STOP command, cannot specify directories &/or output file'); + } + # Only valid to start/stop if no directories have been given + return ($iCommand, $iOutFilesDir, \@iDirsToScan,$iWaitingTime, $iRetries); + } + # Something else has gone wrong. So print usage. + Usage("Unknown command $iCommand"); +} + +################################################################################ +# Usage # +# Inputs: Optional error message # +# Outputs: Usage information for the user. # +# Remarks: None # +################################################################################ +sub Usage +{ + my $iErrorMsg = shift; + + if ($iErrorMsg) + { + print STDERR "\nERROR: $iErrorMsg.\n"; + } + + print <