Date problem in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date problem in perl
# 1  
Old 07-15-2009
Date problem in perl

Hi,

My script is here--

Code:
#!/usr/bin/perl
no warnings "uninitialized";
use File::Copy;
use File::stat;
use Time::Local;
use IO::Handle;
use DateTime;
use Getopt::Long;
use File::Glob ':glob';


my $Summary;
my $Individual;
my $Diagnostics;
my $All;
my $help;

main();

sub main
{
	$result = GetOptions ("LogDir=s" => \$LogDir,
                          "Summary"   => \$Summary,   
                          "Individual=s"   => \$Individual ,       
					      "Diagnostics=s"	=> \$Diagnostics,
					      "Prefix=s" => \$Prefix,
					      "All"  => \$All,
                          "help"  => \$help); 
	usage_help() 	if($help);
	usage_help()    unless($Prefix);
	usgage_help()   unless($LogDir);
		
if($LogDir)
{
	printf "LOG DIR = $LogDir\n";
	die "Log dir '$LogDir' doesn't exist" unless -d $LogDir;
}

$glob_path = "$LogDir/${Prefix}*";
@log_paths = glob $glob_path or die "No files found in '$glob_path'";
#printf "log files = \n";
#print @log_paths;
#printf "\n";

if($Summary)
{
	process_summaryreport (@log_paths);
}

						
# This function tells the usage of the script.
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
	printf "Example:-> perl WFLogStat.pl --LogDir = <DirName if current then put '.'> --Prefix = <arcotwebfort> --Summary";
    printf "Example:-> perl WFLogStat.pl --LogDir = <DirName if current then put '.'> --Prefix = <arcotwebfort> --Individual=ArcotID/QnA/OTP/UP/ALL/ArcotID_Expired/ArcotID_Reset/ArcotID_Revoke/Total/UserQnA";
    printf "Example:-> perl WFLogStat.pl --LogDir = <DirName if current then put '.'> --Prefix = <arcotwebfort> --Diagnostics=User_Name/System ";
EOF
	

						
}

# This function in turn calls many functions which give us the summary about the AOK webfort logs.
sub process_summaryreport
{
	printf "in process summary\n";
	
	
	Avg_Time_Taken_Per_Transaction (@log_paths);
	

}


# This function gives the Average time taken for a transaction to complete. The transaction can be for ArcotID
# or QnA or OTP or User Password.

sub Avg_Time_Taken_Per_Transaction 
{
	avg_time_taken_in_UP(@log_paths);
	avg_time_taken_in_QnA(@log_paths);
	avg_time_taken_in_OTP(@log_paths);
	

}
sub avg_time_taken_in_QnA
{
	
	die if not @_;
	my @log_files = @_;
	open(AVG_OUT,">avg_time") or die "cannot create file avg_time for writing";
	my %mon2num = qw(
		 Jan 1  Feb 2  Mar 3  Apr 4  May 5  Jun 6
		 Jul 7  Aug 8  Sep 9  Oct 10 Nov 11 Dec 12
		);

    my ( $start_dt, $end_dt );

	for my $log_file (@log_files) 
	{ 
		open my $log, '<', $log_file or die "Can't open '$log_file' for reading."; 
		printf AVG_OUT "Processing file $log_file...\n"; 
		while( <$log> ) 
		{ 
			s{\s+\z}{};
			#m/^\s*\w+\s+(\w+)\s+(\d+)\s+(\d\d:\d\d:\d\d\.\d\d\d)\s+(\d+)\s+..*pid\s+(\d+)\s+tid\s+(\d+):..*RiskServer : Read.*/i)
		    if (/(?:Entering|Exiting) QnAModule::authenticate/)
			{
				$end_dt = '';
				my @dtA = split;
				my @time = split /[:.]/, $dtA[3];
				
					( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
					(
					year       => $dtA[4],
					month      => $mon2num{ $dtA[1] },
					day        => $dtA[2],
					hour       => $time[0],
					minute     => $time[1],
					second     => $time[2],
					nanosecond => $time[3],
					);
				

			if ($end_dt && $start_dt)
			{
				print AVG_OUT "start: ", $start_dt, "\n";
			    print AVG_OUT "end: ",   $end_dt,   "\n";
				my $e = $end_dt->subtract_datetime($start_dt);
				printf	AVG_OUT "elapsed time for QnA Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
                $e->years, $e->months, $e->weeks, $e->days, $e->hours,
                $e->minutes, $e->seconds, $e->nanoseconds;

		     }
	    }
     }
	 close $log or warn;
   }
   close (AVG_OUT);
}

sub avg_time_taken_in_OTP
{
	
	die if not @_;
	my @log_files = @_;
	open(AVG_OUT,">>avg_time") or die "cannot create file avg_time for writing";

	my %mon2num = qw(
		 Jan 1  Feb 2  Mar 3  Apr 4  May 5  Jun 6
		 Jul 7  Aug 8  Sep 9  Oct 10 Nov 11 Dec 12
		);

    my ( $start_dt, $end_dt );

	for my $log_file (@log_files) 
	{ 
		open my $log, '<', $log_file or die "Can't open '$log_file' for reading."; 
		printf AVG_OUT "Processing file $log_file...\n"; 
		while( <$log> ) 
		{ 
			s{\s+\z}{};
	        if (/(?:Entering|Exiting) OTPAuthModule::authenticate/)
			{
				$end_dt = '';
				my @dtA = split;
				my @time = split /[:.]/, $dtA[3];
				( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
				(
				year       => $dtA[4],
				month      => $mon2num{ $dtA[1] },
				day        => $dtA[2],
				hour       => $time[0],
				minute     => $time[1],
				second     => $time[2],
				nanosecond => $time[3],
				);

				if ($end_dt && $start_dt)
				{
					print AVG_OUT "start: ", $start_dt, "\n";
					print AVG_OUT "end: ",   $end_dt,   "\n";
					my $e = $end_dt->subtract_datetime($start_dt);
					printf	AVG_OUT "elapsed time for OTP Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
					$e->years, $e->months, $e->weeks, $e->days, $e->hours,
					$e->minutes, $e->seconds, $e->nanoseconds;

		        }
	         }
		}
		close $log or warn;
	}
	close (AVG_OUT);
}

sub avg_time_taken_in_UP
{
	
	die if not @_;
	my @log_files = @_;
	open(AVG_OUT,">>avg_time") or die "cannot create file avg_time for writing";
	my %mon2num = qw(
		 Jan 1  Feb 2  Mar 3  Apr 4  May 5  Jun 6
		 Jul 7  Aug 8  Sep 9  Oct 10 Nov 11 Dec 12
		);

    my ( $start_dt, $end_dt );

	for my $log_file (@log_files) 
	{ 
		open my $log, '<', $log_file or die "Can't open '$log_file' for reading."; 
		printf AVG_OUT "Processing file $log_file...\n"; 
		while( <$log> ) 
		{ 
			    s{\s+\z}{};
				if (/(?:Entering|Exiting) UPAuthModule::authenticate/) 
				{
					$end_dt = '';
					my @dtA = split;
					my @time = split /[:.]/, $dtA[3];
					( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
					(
					year       => $dtA[4],
					month      => $mon2num{ $dtA[1] },
					day        => $dtA[2],
					hour       => $time[0],
					minute     => $time[1],
					second     => $time[2],
					nanosecond => $time[3],
					);

				if ($end_dt && $start_dt)
				{
					print AVG_OUT "start: ", $start_dt, "\n";
					print AVG_OUT "end: ",   $end_dt,   "\n";
					my $e = $end_dt->subtract_datetime($start_dt);
					printf	AVG_OUT "elapsed time for User Password Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
					$e->years, $e->months, $e->weeks, $e->days, $e->hours,
					$e->minutes, $e->seconds, $e->nanoseconds;

			    }
	         }
		}
		close $log    or warn;
      }
	close (AVG_OUT);
	
		
}

When i run the perl script i get this warning , which i want to remove.
The output is coming fine.

I am running the script like this--

Code:
C:\Perl Script>perl WFLogStat.pl --LogDir=. --Prefix=arcotwebfort --Summary

when i run the script , i get this messages--

The 'hour' parameter (undef) to DateTime::new was an 'undef', which is not one o
f the allowed types: scalar
 at C:/Perl/lib/Params/ValidatePP.pm line 634
        Params::Validate::__ANON__('The \'hour\' parameter (undef) to DateTime::
new was an \'unde...') called at C:/Perl/lib/Params/ValidatePP.pm line 485
        Params::Validate::_validate_one_param('undef', 'HASH(0x183182c)', 'HASH(
0x1d39618)', 'The \'hour\' parameter (undef)') called at C:/Perl/lib/Params/Vali
datePP.pm line 345
        Params::Validate::validate('ARRAY(0x1c2d24c)', 'HASH(0x1d3978c)') called
 at C:/Perl/lib/DateTime.pm line 171
        DateTime::new('undef', 'year', 'undef', 'month', 'undef', 'day', 'undef'
, 'hour', 'undef', ...) called at WFLogStat.pl line 372
        main::avg_time_taken_in_UP('./arcotwebfort.log', './arcotwebfort_20May09
_00_03_55.log', './arcotwebfort_20May09_15_12_18.log', './arcotwebfort_20May09_2
3_32_56.log', './arcotwebfort_29May09_18_29_45.log', './arcotwebfort_29May09_19_
17_47.log') called at WFLogStat.pl line 231
        main::Avg_Time_Taken_Per_Transaction('./arcotwebfort.log', './arcotwebfo
rt_20May09_00_03_55.log', './arcotwebfort_20May09_15_12_18.log', './arcotwebfort
_20May09_23_32_56.log', './arcotwebfort_29May09_18_29_45.log', './arcotwebfort_2
9May09_19_17_47.log') called at WFLogStat.pl line 182
        main::process_summaryreport('./arcotwebfort.log', './arcotwebfort_20May0
9_00_03_55.log', './arcotwebfort_20May09_15_12_18.log', './arcotwebfort_20May09_
23_32_56.log', './arcotwebfort_29May09_18_29_45.log', './arcotwebfort_29May09_19
_17_47.log') called at WFLogStat.pl line 84
        main::main() called at WFLogStat.pl line 57

I have removed some part of code so the warning lines may not match.

Kindly suggest what is wrong here.

The sample log file is--

Code:
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: Entering UPAuthModule::authenticate
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: UPAuth Session Id :[1:10090433]
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: UpAuth User DB Query is based on username[123456] and groupID[1007]:
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: Number of rows fetched from DB : 1
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: UPAuth SUCCESS for user[123456]
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: Exiting UPAuthModule::authenticate

One more thing when i run the program individually, i do not get any errors.

Kindly suggest what can be wrong here.

Thanks
NT

---------- Post updated 07-15-09 at 02:43 AM ---------- Previous update was 07-14-09 at 04:25 AM ----------

Hi,

Any suggestions regarding what might cause the problem in my script will be a great help to me.
Kindly suggest something.

Thanks
NT
# 2  
Old 07-15-2009
Looks like the error is coming from this line. Can you post the code around this line please.
Code:
DateTime::new('undef', 'year', 'undef', 'month', 'undef', 'day', 'undef'
, 'hour', 'undef', ...) called at WFLogStat.pl line 372

# 3  
Old 07-15-2009
Here is the code
Code:
sub avg_time_taken_in_UP
{
	
	die if not @_;
	my @log_files = @_;
	open(AVG_OUT,">>avg_time") or die "cannot create file avg_time for writing";
	my %mon2num = qw(
		 Jan 1  Feb 2  Mar 3  Apr 4  May 5  Jun 6
		 Jul 7  Aug 8  Sep 9  Oct 10 Nov 11 Dec 12
		);

    my ( $start_dt, $end_dt );

	for my $log_file (@log_files) 
	{ 
		open my $log, '<', $log_file or die "Can't open '$log_file' for reading."; 
		printf AVG_OUT "Processing file $log_file...\n"; 
		while( <$log> ) 
		{ 
			    s{\s+\z}{};
				if (/(?:Entering|Exiting) UPAuthModule::authenticate/) 
				{
					$end_dt = '';
					my @dtA = split;
					my @time = split /[:.]/, $dtA[3];
					( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
					(
					year       => $dtA[4],
					month      => $mon2num{ $dtA[1] },
					day        => $dtA[2],
					hour       => $time[0],
					minute     => $time[1],
					second     => $time[2],
					nanosecond => $time[3],
					);

The "my @dtA = split;" line looks suspicious but I am not a Perl guru.
# 4  
Old 07-20-2009
Quote:
Originally Posted by BubbaJoe
Looks like the error is coming from this line. Can you post the code around this line please.
Code:
DateTime::new('undef', 'year', 'undef', 'month', 'undef', 'day', 'undef'
, 'hour', 'undef', ...) called at WFLogStat.pl line 372


This is the code around the problem,

Code:
sub avg_time_taken_in_UP
{
	
	die if not @_;
	my @log_files = @_;
	open(AVG_OUT,">>avg_time") or die "cannot create file avg_time for writing";
	my %mon2num = qw(
		 Jan 1  Feb 2  Mar 3  Apr 4  May 5  Jun 6
		 Jul 7  Aug 8  Sep 9  Oct 10 Nov 11 Dec 12
		);

    my ( $start_dt, $end_dt );

	for my $log_file (@log_files) 
	{ 
		open my $log, '<', $log_file or die "Can't open '$log_file' for reading."; 
		printf AVG_OUT "Processing file $log_file...\n"; 
		while( <$log> ) 
		{ 
			    s{\s+\z}{};
				if (/(?:Entering|Exiting) UPAuthModule::authenticate/) 
				{
					$end_dt = '';
					my @dtA = split;
					my @time = split /[:.]/, $dtA[3];
					( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
					(
					year       => $dtA[4],
					month      => $mon2num{ $dtA[1] },
					day        => $dtA[2],
					hour       => $time[0],
					minute     => $time[1],
					second     => $time[2],
					nanosecond => $time[3],
					);

				if ($end_dt && $start_dt)
				{
					print AVG_OUT "start: ", $start_dt, "\n";
					print AVG_OUT "end: ",   $end_dt,   "\n";
					my $e = $end_dt->subtract_datetime($start_dt);
					printf	AVG_OUT "elapsed time for User Password Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
					$e->years, $e->months, $e->weeks, $e->days, $e->hours,
					$e->minutes, $e->seconds, $e->nanoseconds;

			    }
	         }
		}
		close $log    or warn;
      }
	close (AVG_OUT);
	
		
}

Thanks
Namish

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

2. Shell Programming and Scripting

Fetch date of 7 years back from current date in Perl

$beginDate = substr(DateCalc("today", "-7Days"),0,8); This fetches the date 7 days back Can I fetch the date before 7 years from todays date in Perl using same syntax Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies

3. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

4. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

5. Programming

Problem with perl pattern for date

Hello Friends, I have been struck with a perl script for quite some time now. I have a log file which gives a date which is sometimes coming in this format Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 15:12:50 or sometimes in this format Script... (2 Replies)
Discussion started by: achak01
2 Replies

6. Shell Programming and Scripting

Problem with date in perl!!

Hi All, I am facing an issue with perl.. I have a perl script that executes the stored procedure and puts the data in a file. In stord proc we have one date column also. In table from which it is fetching the data, date is in the form "14/03/2010 00:00:00.000" (DD/MM/YYYY). But when the perl... (4 Replies)
Discussion started by: abhisharma23
4 Replies

7. Shell Programming and Scripting

problem with date in perl

hi guys, i have a variable date that stores the current date....now i need to subtract 2 minutes from it...can someone tell me how to do it in perl.... (5 Replies)
Discussion started by: niteesh_!7
5 Replies

8. Programming

Date time problem while executing perl script.

Hi All, This Monday 15th March 2010, i have faced a weired issue with my Perl script execution, this script is scheduled to run at 1 minute past midnight on daily basis ( 00:01 EST ) generally for fetching previous business date , say if it is Monday it should give last Friday date, for Tuesday... (0 Replies)
Discussion started by: ravimishra
0 Replies
Login or Register to Ask a Question