wrong output in perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wrong output in perl script
# 1  
Old 07-02-2009
wrong output in perl script

Hi,

Here is my piece of code--

Code:
#!/usr/bin/perl

my $Time_Stamp ;
my $User_Name;
my $Success;
my $Failure;
my $ErrorCode;
my $ErrorMsg;
my $logDir = $ARGV[0]; 
my $logPrefix = $ARGV[1]; 

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,">temp12") or die "cannot create file temp1 for writing";
	print "Processing file $logFile...\n";
	

	OUTER: while( $line = <$log> )
	{

		 chomp($line);
		 if ($line =~ /^(.*)INFO:.*QNA Step - AUTH IN PROGRESS/) 
		 {
				$Time_Stamp = $1;
				printf FP_OUT "$Time_Stamp,";
				QnA_search_for_sucess_or_failure() ;
				#QnA_search_for_userID() ;
				next OUTER;

		 }

	 }
}

 


sub QnA_search_for_sucess_or_failure
 
{
OUTER1: while ( $line = <$log> )

{
	  if ($line =~ /QNA Auth.*Success\s*and\s*Complete/)

	   {
				printf FP_OUT "Success,";
				print STDOUT  "In Success,\n";
				$ErrorMsg="null";
				while ( $line = <$log> )
				{
					 if ($line =~ /ArAuthFrameworkImpl::doPostAuth.*Authentication\s*mechanism\s*returned\s*\[(..*)\]\s*for\s*AuthIdentity\s*\[(..*)\]/)

						 {
							   print "$2\n";
							  printf FP_OUT "$2, ${1}, $ErrorMsg\n";
							  last OUTER1;

						 }
				 }
				 
	   }
	   if($line =~ /Message.*QNA\s*Auth\s*Failed\((..*)\).*/)
	   {
				 $ErrorMsg=$1;
				 printf FP_OUT  "Failure,";
				 print STDOUT  "In Failure,\n";
				 while ( $line = <$log> )
					  {
						 if ($line =~ /ArAuthFrameworkImpl::doPostAuth.*Authentication\s*mechanism\s*returned\s*\[(..*)\]\s*for\s*AuthIdentity\s*\[(..*)\]/)

						  {
							  
							  print "$2\n";
							  printf FP_OUT "$2, ${1}, $ErrorMsg\n";
							  last OUTER1;
						  }

					  }

				 
	   }
	  }
	  
}

The below snippet is taken from the logfile.I am using while loops because there are many lines above and inbetween this snippet.
Code:
Tue May 19 22:55:13.649 2009 Morocco Standard Time INFO:    pid 2172 tid 3412: 160: 10083504: QNA Step - AUTH IN PROGRESS
Tue May 19 22:55:13.649 2009 Morocco Standard Time INFO:    pid 2172 tid 3412: 160: 10083504: QNA Auth - Success and Complete, Returning SUCCESS
Tue May 19 22:55:13.665 2009 Morocco Standard Time INFO:    pid 2172 tid 3412: 17: 10083504: ArAuthFrameworkImpl::doPostAuth::1:10083487:: Authentication mechanism returned [0] for AuthIdentity [12345]


and for QnA failure the line comes like this in place of success line--
Tue May 19 22:56:21.962 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 160: 10083554: Err[115261735], Message: QNA Auth Failed(Invalid Credentials), Repeating the challenge and Returning FAILED

when i ran the program like this--
Code:
C:\Perl Script>perl  QnA_Authentication.pl . logfile.txt
Processing file ./logfile.txt...
In Success,
01503164
In Success,
01822755
In Failure,
01401058
Processing file ./logfile.txt.bak...

but in output file that is temp12, it is not printing anything.
Kindly suggest wha is wrong here.
# 2  
Old 07-03-2009
You need to flush the output every now and then.

select FP_OUT; $|=1; select STDOUT;
# 3  
Old 07-03-2009
Seems to be working fine

I used the log information as u had given above.


The o/p is

Processing file xxxxxxxxxxxxxxxxxxxxxxxxxx/file.txt...

In Success,
12345


In temp12,
Tue May 19 22:55:13.649 2009 Morocco Standard Time ,Success,12345, 0, null


is this what you expecting?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Output coming in wrong format....

Hi team, getting output logs wrong in different format from telnet script ... getting Output.txt macro_outdoor_dist-6.0.0(v4_0_2) DN:1.3.903 (1101:100:11w:500:3:2:103:aa) macro_outdoor_dist-8.1.0(v3_1_0) DN:1.3.409 (N/A)... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

2. Shell Programming and Scripting

Executing perl script in Linux gives :Exec format error. Wrong Architecture

i have perl script that used to be working great , once i edit it in windows and convert it to UTF-8 and then via FTP return it . also did: chmod +x foo.pl and then when i try to run it : ./foo.pl im getting this error: ./foo.pl: Exec format error. Wrong Architecture.... (4 Replies)
Discussion started by: umen
4 Replies

3. Shell Programming and Scripting

Perl Script output

Hi All, I have an expect script that I would like a perl script to call in order to login to a node and run in a single command. The command being running is a log of events so has lots of data that will be output. I would like to output that data to a file. Would anyone be kind enought... (1 Reply)
Discussion started by: mutley2202
1 Replies

4. Shell Programming and Scripting

What is wrong with my perl script?

i managed to write a perl script for nagios. now, the script works. but i think there's somethign wrong with the exit codes. because the script doesn't show the output of the results in nagios, it instead shows null. please tell me what i'm doing wrong here: #!/usr/local/bin/perl use... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

Perl CGI. no output until backend script is done

It is a basic Perl CGI question, I want to print out "Processing ... " while backend script /script/wait.pl is still running. But acctually, nothing appeared in browser untill /script/wait.pl finished. print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print... (4 Replies)
Discussion started by: honglus
4 Replies

6. Shell Programming and Scripting

Perl...getting wrong output?

Good morning! Im trying to write and learn at the same time a simple script. fTHe script should tell me if a number is odd or even/ #!/usr/bin/perl $num = 10; $string1 = "This number is odd"; $string2 = "This number is even"; if ($num /= 2) { print "$string1\n"; }else{ ... (3 Replies)
Discussion started by: bigben1220
3 Replies

7. Shell Programming and Scripting

Using output of perl script in shell

Hi, I have a perl script which prints the epoch value of given date. I want to use its output in a shell script.Can someone suggest me how to do it. Thanks and Regards Jyothi (4 Replies)
Discussion started by: jyothi_wipro
4 Replies

8. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

9. Shell Programming and Scripting

error in output of perl script

Hi, This is my piece of code. my $logFile = $ARGV; die "usage: $0 <logFile>" unless $logFile; die "Logfile $logFile doesn't exist" unless -f "$logFile"; open(my $log, "<", $logFile) or die "Can't open $logFile for reading."; print "Processing file $logFile...\n"; #my $authenticates... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. Shell Programming and Scripting

Perl Script issue. What am I doing wrong?

#!/usr/local/bin/perl open (MYFILE, 'logs_report'); while (<MYFILE>) { $rec=$_; chomp ($rec); @arr=split(/ /,$rec); print $rec,"\n" if ($arr!~/OK/); open (MYF, '>data.txt'); print $rec,"\n" if ($arr!~/OK/); close (MYF); (14 Replies)
Discussion started by: SkySmart
14 Replies
Login or Register to Ask a Question