Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help finding tomorrow today.

Status
Not open for further replies.

pcutler

Technical User
Jan 18, 2002
59
CA
Several years ago, I wrote a script that looks for a file with today’s date, renames it and then FTP’s the file to a web server. It then checks to see if the transfer succeeded and sends out an e-mail to let me know if the file made it or not.

I had scheduled the script to run at 12:10 a.m. Now I need to run the script at 4:30 p.m.

The problem is, while I can find today’s date easily, I’m having a lot of trouble finding tomorrow.

My scripting experience is limited, and I’d appreciate your suggestions.

Peter.
 
Code:
my $now = time;
my $later = time + (60 * 60 * 24);

my ($sec, $min, $hour, $day, $month, $year) = &datetime($later);

print "$year $month $day $hour $min $sec\n";


sub datetime {
	my $epoch = shift @_;
    my ($sec, $min, $hour, $day, $month, $year) = localtime($epoch);
    $month++;
    $year  += 1900;
    $_ = sprintf("%02d", $_) for ($sec, $min, $hour, $day, $month);
	return($sec, $min, $hour, $day, $month, $year);
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thank you Travis,

That looks like it will work.

pc
 
I don't get how this has anything to do with scheduling when the script runs. Scheduling a perl script to run is generally not handled by the perl script.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I think he just has a job that's checking the transfer of the file. To do that he is looking at a timestamp in the file name. The timestamp is probably in GMT and that is why the timestamp is showing up with a future date.

As a thought.. if that is why it is happening he can stop using localtime and just use gmtime. Get rid of the whole math setup :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
You are correct, I need to find a file with tomorrows date in it's file name, rename it ant then FTP it to a web server.

At one time, I did switch to using GMT, but using GMT won't allow me to run the script early enough in the day.

The person responsible for generating this file has a bad habit of not following the naming convention agreed on, resulting in the transfer failing.

I've had to resort to running the script before they leave for the day, so we can make sure the transfer succeeds.

Thanks to the suggestion Travis made, I can run the script at 5:00 p.m. local time.

Thanks Travis!
 
Maybe you can eradicate the problem at source. Give them a Perl script they can run that generates the file name, so they won't be able to screw up. Although as the saying goes, "it is impossible to make something foolproof, because fools are so ingenious..."

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top