
perlisgreat
Novice
Jun 29, 2009, 7:37 AM
Post #35 of 36
(17110 views)
|
Hi Larry, here is my piece of code,
#!/usr/bin/perl use Getopt::Long; my $result; my $Summary; my $Individual; my $Diagnostics; my $All; my $help; $result = GetOptions ("LogDir=s" => \$LogDir, "Logfile=s" => \$Logfile, "Summary" => \$Summary, "Indiviual=s" => \$Individual , "Diagnostics=s" => \$Diagnostics, "All" => \$All, "help" => \$help); sub usage_help { printf <<EOF Script usage is Scriptname --Summary Scriptname --Indiviual=Arcotid/QNA/OTP/Password/All/Arcotid Revoke/Expire/All/QNA number Scriptname --Diagnostics=username/system Scriptname --ALL EOF } usage_help() if($help); usage_help() unless($Logfile); if($Summary) { Total_Number_Of_Transactions() ; } sub Total_Number_Of_Transactions { my $logfile = $Logfile; my $logDir = $ARGV[1]; my $logPrefix = $ARGV[2]; #die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't exist" unless -d "$logDir"; for my $logFile ( glob("$logDir/${logPrefix}*") ) { open($log, "<", $logFile) or die "Can't open $logFile for reading."; open(FP_OUT,">total_transactions") or die "cannot create file total_transactions for writing"; } my $Total_QnA_Count = 0; my $Total_OTP_Count = 0; my $Total_UP_Count = 0; my $Total_ArcotID_Count = 0; my $Success_QnA_Count =0; my $Failure_QnA_Count = 0; my $Success_ArcotID_Count = 0; my $Failure_ArcotID_Count = 0; my $Success_OTP_Count = 0; my $Failure_OTP_Count = 0; my $Success_UP_Count = 0; my $Failure_UP_Count = 0; OUTER: while( $line = <$log> ) { $line =~ tr/\r\n//d; if ($line =~ /Arcot Native Server: recvd AA_BIN_MSG_VER_CHG/) { while ($line = <$log>) { if ($line =~ /ArcotID\s*Auth\s*SUCCESS.*/) { $Success_ArcotID_Count++; next OUTER; } elsif ($line =~ /Auth failed.*/) { $Failure_ArcotID_Count++; next OUTER; } } } if ($line =~ /QNA Step - AUTH IN PROGRESS/) { while ($line = <$log>) { if ($line =~ /QNA Auth - Success.*/) { $Success_QnA_Count++; next OUTER; } elsif ($line =~ /Message: QNA Auth Failed.*/) { $Failure_QnA_Count++; next OUTER; } } } if ($line =~ /Entering OTPAuthModule::authenticate/) { while ($line = <$log>) { if ($line =~ /OTP SUCCESS.*/) { $Success_OTP_Count++; next OUTER; } elsif ($line =~ /Message: OTP FAILED.*/) { $Failure_OTP_Count++; next OUTER; } } } if ($line =~ /Entering UPAuthModule::authenticate/ .. /Sending Invalid credential/) { while ($line = <$log>) { if ($line =~ /UPAuth SUCCESS.*/) { $Success_UP_Count++; next OUTER; } elsif ($line =~ /UPAuth FAILED.*/) { $Failure_UP_Count++; next OUTER; } } } } $Total_ArcotID_Count = $Success_ArcotID_Count + $Failure_ArcotID_Count ; $Total_QnA_Count = $Success_QnA_Count + $Failure_QnA_Count ; $Total_OTP_Count = $Success_OTP_Count + $Failure_OTP_Count ; $Total_UP_Count = $Success_UP_Count + $Failure_UP_Count ; printf FP_OUT "Total ArcotID count is $Total_ArcotID_Count\n"; printf FP_OUT "Total QnA count is $Total_QnA_Count\n"; printf FP_OUT "Total OTP count is $Total_OTP_Count\n"; printf FP_OUT "Total User Password count is $Total_UP_Count\n"; close(FP_OUT); close($log); } i am accessing this as--
C:\Perl Script\Sample Programs>perl sample2.pl --Summary --LogDir="C:\Perl Scrip\Sample Programs" --Logfile=arcotwebfort_20May09 Log dir doesn't exist at sample2.pl line 48. I got the above error when i ran like that. I tried with putting (.) also in place of directory name but no luck. Am i accessing the files correctly. One more thing i would like to ask is-- the does not give me correct out when i ran it without getopt::long. And now it is not compiling. Can you suggest me what is wrong here. What modifications i need to do to get rid of this problem. Thanks NT
|