Sponsored Content
Top Forums Programming Date time problem while executing perl script. Post 302404856 by ravimishra on Wednesday 17th of March 2010 10:42:31 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
after(n)						       Tcl Built-In Commands							  after(n)

__________________________________________________________________________________________________________________________________________________

NAME
after - Execute a command after a time delay SYNOPSIS
after ms after ms ?script script script ...? after cancel id after cancel script script script ... after idle ?script script script ...? after info ?id? _________________________________________________________________ DESCRIPTION
This command is used to delay execution of the program or to execute a command in background sometime in the future. It has several forms, depending on the first argument to the command: after ms Ms must be an integer giving a time in milliseconds. The command sleeps for ms milliseconds and then returns. While the command is sleeping the application does not respond to events. after ms ?script script script ...? In this form the command returns immediately, but it arranges for a Tcl command to be executed ms milliseconds later as an event handler. The command will be executed exactly once, at the given time. The delayed command is formed by concatenating all the script arguments in the same fashion as the concat command. The command will be executed at global level (outside the context of any Tcl procedure). If an error occurs while executing the delayed command then the bgerror mechanism is used to report the error. The after command returns an identifier that can be used to cancel the delayed command using after cancel. after cancel id Cancels the execution of a delayed command that was previously scheduled. Id indicates which command should be canceled; it must have been the return value from a previous after command. If the command given by id has already been executed then the after can- cel command has no effect. after cancel script script ... This command also cancels the execution of a delayed command. The script arguments are concatenated together with space separators (just as in the concat command). If there is a pending command that matches the string, it is cancelled and will never be executed; if no such command is currently pending then the after cancel command has no effect. after idle script ?script script ...? Concatenates the script arguments together with space separators (just as in the concat command), and arranges for the resulting script to be evaluated later as an idle callback. The script will be run exactly once, the next time the event loop is entered and there are no events to process. The command returns an identifier that can be used to cancel the delayed command using after can- cel. If an error occurs while executing the script then the bgerror mechanism is used to report the error. after info ?id? This command returns information about existing event handlers. If no id argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the after command for this interpreter. If id is supplied, it specifies an existing handler; id must have been the return value from some previous call to after and it must not have triggered yet or been cancelled. In this case the command returns a list with two elements. The first element of the list is the script associated with id, and the second element is either idle or timer to indicate what kind of event handler it is. The after ms and after idle forms of the command assume that the application is event driven: the delayed commands will not be executed unless the application enters the event loop. In applications that are not normally event-driven, such as tclsh, the event loop can be entered with the vwait and update commands. SEE ALSO
bgerror(n), concat(n), update(n), vwait(n) KEYWORDS
cancel, delay, idle callback, sleep, time Tcl 7.5 after(n)
All times are GMT -4. The time now is 06:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy