Date time problem while executing perl script.


 
Thread Tools Search this Thread
Top Forums Programming Date time problem while executing perl script.
# 1  
Old 03-17-2010
Java 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 it should get me last Monday date, for Wednesday it should fetch last Tuesday date and so on ...

but when it ran this monday 15th march it behaved in weired manner which i have never seen it happen in last 3 - 4 month, even though this script was executed at 00:01 EST Mar 15, 2010 it gave me output date for last Thursday date ( which i have mentioned only for cases where datatime > 20 hrs )

Can someone explain me this behavior? is there anything to do with DST changes which US entered this Sunday???

Below is the Perl script for reference.
Code:
bash-2.05$ cat prev_biz_date_yyyymmdd.pl
#!/usr/local/bin/perl

use POSIX;

our $nextDay;
our $dayOfWeek;
our $datetime;

$dayOfWeek =`date +%w`;chomp($dayOfWeek);

# Get My Date
my $info = scalar localtime(time);
$info =~ s/ +/ /g;
($dtime) = (split(/\:/,$info))[0];
($datetime) = (split(/ /,$dtime))[3];

our $outFile = "/ilx/ftp/date/prev_biz_date_yymmdd.date";

# Create some semaphore
`cat /dev/null > $outFile`;

SWITCH: {
        if ($dayOfWeek == 0){
            $WorkDate = get_date(2);
             print "$WorkDate\n";
             last SWITCH;   }
        if ($dayOfWeek == 1){
            $WorkDate = get_date(3);
             print "$WorkDate\n";
             last SWITCH;   }
        if ($dayOfWeek == 2){
            $WorkDate = get_date(1);
             print "$WorkDate\n";
             last SWITCH;   }
        if ($dayOfWeek == 3){
            $WorkDate = get_date(1);
             print "$WorkDate\n";
             last SWITCH;   }
        if ($dayOfWeek == 4){
            $WorkDate = get_date(1);
             print "$WorkDate\n";
             last SWITCH;   }
        if ($dayOfWeek == 5){
            $WorkDate = get_date(1);
             print "$WorkDate\n";
             last SWITCH;   }
        if ($dayOfWeek == 6){
            $WorkDate = get_date(1);
             print "$WorkDate\n";
             last SWITCH;   }

}

open (OUT,"> $outFile ") || die "$!\n";
        print OUT "$WorkDate\n";
close OUT;

sub get_date {

        our $wkday = shift;chomp($wkday);

        if ($datetime <= 20) {
                $WorkD = strftime("%Y%m%d", localtime(time - ($wkday * 86400)));
        }else{
                $WorkD = strftime("%Y%m%d", localtime(time - (($wkday + 1) * 86400)));
        }
        return $WorkD;
};


Last edited by jim mcnamara; 03-17-2010 at 12:49 PM.. Reason: code tags please
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append date to an executing script

This works except the date being sent to this script. Is it because I am trying to write to an executing script? Is there a better way? date '+%m-%d-%Y_%I:%M-%p'>> Send_Email.sh CONTENT="Backup to Maxtor Drive has occured." echo "Sending email." /usr/sbin/ssmtp -t << EOF To:... (1 Reply)
Discussion started by: drew77
1 Replies

2. Shell Programming and Scripting

Error executing date script

Hi, Seen below is a simple date script. #! /bin/ksh VL = `date +%m/%d` VL1 = `TZ=GMT+24 date +%m/%d` VL2 = `TZ=GMT+48 date +%m/%d` VL3 = `TZ=GMT+72 date +%m/%d` VL4 = `TZ=GMT+96 date +%m/%d` VL5 = `TZ=GMT+120 date +%m/%d` echo $VL echo $VL1 echo $VL2 echo $VL3 echo $VL4 echo... (2 Replies)
Discussion started by: jayadanabalan
2 Replies

3. Shell Programming and Scripting

Perl:Script to append date and time stamp

Help with Perl script : I have a web.xml file with a line <display-name>some_text_here</display-name> Need to append the current date and time stamp to the string and save the XML file Something like <display-name>some_text_here._01_23_2014_03_56_33</display-name> -->Finally want... (5 Replies)
Discussion started by: gaurav99
5 Replies

4. 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

5. Shell Programming and Scripting

Problem executing perl script on remote server

Hello, I am running in to a problem running a perl script on a remote server. I can run a simple script test.pl which contains just a print statment without issue by running ssh root@1.2.3.4 perl test.pl However, I have a more complex script that does not execute as expected. I think I... (3 Replies)
Discussion started by: colinireland
3 Replies

6. Shell Programming and Scripting

Creating a date (without time) in perl

I have a perl script that automatically runs on Mondays. I need to have it create a variable for last Monday's date thru that Sunday's date. example: 04-01-2011 thru 04-08-2011 Its reporting numbers for the previous week beginning with Monday and ending on Sunday. So i dont have to go in... (7 Replies)
Discussion started by: bbraml
7 Replies

7. Shell Programming and Scripting

Date and Time in PERL

Hi, I want to get the current date and time and subtract 1 day to get to the previous day? I see timelocal( ) and (time) etc. How do I code this in PERL to get the previous day? Thanks Nurani (2 Replies)
Discussion started by: nurani
2 Replies

8. Shell Programming and Scripting

Script to capture date/time in seconds in PERL... Cant understand errors

I'm Using this script to find the time of a file. I'm very much new to PERL and found this script posted by some one on this forum. It runs perfectly fine, just that it gives me following errors with the accurate output as well. I jus want the output to be stored in another file so that i can... (0 Replies)
Discussion started by: bankimmehta
0 Replies

9. Shell Programming and Scripting

Problem executing setuid script in perl-5.8.6

Hi, I have a script (a.pl) that can be run by anyone. The script internally has to read a file and write into few files which are owned by user 'myUser'. Has to read the following file: -rwx------ 1 myuser myuser 4986 Aug 20 18:11 my.file Has to write into following files: ... (0 Replies)
Discussion started by: sarmakdvsr
0 Replies

10. Shell Programming and Scripting

executing a script for a certain amount of time

I am writing a script that takes two parameters: the name of another script and an integer that represents a number of seconds. The script must execute the second script (first parameter) for the specified number of seconds (second parameter), suspend it for the same number of seconds, and continue... (9 Replies)
Discussion started by: ponchorage
9 Replies
Login or Register to Ask a Question