amoura has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks, I have this command updquery -sdate 26-june-2002.02:00:00 -edate 02-july-2002.00:00:00 -brtype golden -status closed , which is a clearcase command I havd this guy in my script and what it does is finding the files that have been changed since last build. -sdate stand for start time and -edate stand for end date , my script should be kroned to run weekely and excute this command. So each week the -edate will be my current date and time the -sdate will the one a week before. any ideas of how to deal with this one , capturing the time and greping and all that :( . I would appreciate some help and tips . thanks

Replies are listed 'Best First'.
Re: kroned Script question
by stajich (Chaplain) on Jul 03, 2002 at 19:49 UTC
    I don't think you need specify the start/end date unless you want override the value of the current time or specify a different time interval. Perl can figure out the current time and add 1 week to that just fine. Here is a relatively verbose example which I hope gives you a starting point. It only uses Date::Manip for determining the date when specified on the cmdline.

    Not sure if you wanted to help on finding the files which actually matched this range too? Readup on localtime to see which array slots code for the values you want and stat to see the information on how to determine when a file was updated/created/last accessed.

    #!/usr/bin/perl -w use strict; use POSIX; use Getopt::Long; use Date::Manip; use constant SECONDS_IN_MINUTE => 60; use constant MINUTES_IN_HOUR => 60; use constant HOURS_IN_DAY => 24; use constant DAYS_IN_WEEK => 7; # set some defaults my $sdate = time; my $weekseconds = SECONDS_IN_MINUTE * MINUTES_IN_HOUR * HOURS_IN_DAY * DAYS_IN_WEEK; my $edate = $sdate + ( $weekseconds ); # which can be overridden by your cmd line options # I didn't add anything for the -brtype etc GetOptions( 'sdate:s' => sub { $sdate = &process_date($_[1])}, 'edate:s' => sub { $edate = &process_date($_[1])}); printf("start time is %s, end time is %s\n", strftime("%d %b %Y %H:%M:%S", localtime($sdate)), strftime("%d %b %Y %H:%M:%S", localtime($edate))); sub process_date { my $d = shift; my $date = &ParseDate($d); if( ! $date ) { die("cannot determine date from $d\n"); } return &UnixDate($date, "%s"); }
      thats help a lot stajich, I have a small question, I am not checking week ahead my current time is the end time , last time I ran my script would be the start time so I tried to fix the script to get it do it that way but was not seccessful :(.
Re: kroned Script question
by DamnDirtyApe (Curate) on Jul 03, 2002 at 19:45 UTC

    Take a look at time, localtime, and strftime in the POSIX module.

    my $now = time ; my $one_week_ago = $now - 604_800 ; # Your chosen method of time/date formatting here...

    _______________
    D a m n D i r t y A p e
    Home Node | Email