#!C:\Perl\Bin\Perl.exe # Enable Pragmatic Modules use warnings ; use strict; # Define Variables and Hashes my $numelements ; my $done = 3 ; my $count = 0 ; my $username = "" ; my %userhash ; my $inputfile = "" ; my $outputfile = "" ; my $userlist = "" ; my $record = "" ; my $bigcounter = 0 ; # Argument testing $numelements = @ARGV ; print "\n$numelements\n" ; # Check for 0 arguments and switches, apply error message if true if ( $numelements == 0 ) { print "\n *** Error : Command-line switches and arguments must be provided. ***\n\n" ; print " $0 -l -u -r \n\n" ; print " -l The relative or absolute path to the webserver logfile.\n" ; print " -u The relative or absolute path to the user list file.\n" ; print " -r The relative or absolute path to the generated report file.\n\n" ; exit 200 ; } # Check to osee that they gave more or less than 6 arguments, appply approproiate error message. if (( $numelements > 0 ) and ( $numelements !~ 6 )) { print "\n *** Error : Too many (or too few) command-line switches and arguments were provided. ***\n\n" ; print " $0 -l -u -r \n\n" ; print " -l The relative or absolute path to the webserver logfile.\n" ; print " -u The relative or absolute path to the user list file.\n" ; print " -r The relative or absolute path to the generated report file.\n\n" ; exit 201 ; } # Check for double switches if (( $ARGV[0] =~ $ARGV[2] ) or ( $ARGV[2] =~ $ARGV[4] ) or ( $ARGV[0] =~ $ARGV[4] )) { print "\n *** Error : Incomplete (or incorrect) command-line switches and arguments were provided. ***\n\n" ; print " $0 -l -u -r \n\n" ; print " -l The relative or absolute path to the webserver logfile.\n" ; print " -u The relative or absolute path to the user list file.\n" ; print " -r The relative or absolute path to the generated report file.\n\n" ; exit 202 ; } # Start a loop to check for all correct switches, and apply input filenames to variables while ( $done != 0 ) { if ( $count == 6 ) { print "\n *** Error : Incomplete (or incorrect) command-line switches and arguments were provided. ***\n\n" ; print " $0 -l -u -r \n\n" ; print " -l The relative or absolute path to the webserver logfile.\n" ; print " -u The relative or absolute path to the user list file.\n" ; print " -r The relative or absolute path to the generated report file.\n\n" ; exit 202 ; } if ( $ARGV[$count] =~ /^-l$/i ) { $inputfile = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-u$/i ) { $userlist = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-r$/i ) { $outputfile = $ARGV[$count + 1] ; $done-- ; } $count = $count + 2 ; } # Check for input file existance and begin to parse file, otherwise display appropriate error message if ( -e $inputfile ) { open( INPUTDATAFILE, "< $inputfile" ) or die " \n\nError: $!\n\n" ; while ( defined( $record = ) ) { if ( $bigcounter == 100000 ) { print "." ; $bigcounter = 0 ; } chomp( $record ) ; if($record =~ /\/\~(c(s|e)[0-9][0-9][0-9][0-9])/) { $username = $1 ; if(exists $userhash{$username}) { $userhash{$username}++; } else{ $userhash{$username}=1 ; } } $bigcounter++ ; } $numelements = %userhash ; print "$numelements\n" ; }else { print "\n *** Error : Webserver logfile '$inputfile' : NOT FOUND. ***\n\n" ; exit 100 ; } # Check for userlist file, or display apropriate error message if ( -e $userlist ) { }else { print "\n *** User list file '$userlist' : NOT FOUND. ***\n\n" ; exit 101 ; } system "( Pause ) " ; #### # Start a loop to check for all correct switches, and apply input filenames to variables while ( $done != 0 ) { if ( $count == 6 ) { print "\n *** Error : Incomplete (or incorrect) command-line switches and arguments were provided. ***\n\n" ; print " $0 -l -u -r \n\n" ; print " -l The relative or absolute path to the webserver logfile.\n" ; print " -u The relative or absolute path to the user list file.\n" ; print " -r The relative or absolute path to the generated report file.\n\n" ; exit 202 ; } if ( $ARGV[$count] =~ /^-l$/i ) { $inputfile = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-u$/i ) { $userlist = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-r$/i ) { $outputfile = $ARGV[$count + 1] ; $done-- ; } $count = $count + 2 ; }