Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: executing perl script at a certain time/day

by Chief of Chaos (Friar)
on Dec 06, 2002 at 07:41 UTC ( [id://218003]=note: print w/replies, xml ) Need Help??


in reply to executing perl script at a certain time/day

Hi,
another way is to compute the difference between NOW and starttime and to sleep this time in seconds.
#!/usr/local/bin/perl -w use strict; use Time::Local; use POSIX qw(ctime difftime mktime); my $starttime = '08.12.02 03:00:00'; my $nowtime = time; #time in sec since 1970 my $sTime = 0; my $sleepSec = 0; #parsing the input (start) time if ($starttime =~ /^\s*(\d{1,2})\.(\d{1,2})\.(\d{2})\s+(\d{1,2})\:(\d{ +1,2})\:(\d{1,2})\s*$/) { # mktime(sec,min,hr,day,month,year) # month (0..11); year = 0 => 1900 , year = 100 => 2000 $sTime = mktime($6,$5,$4,$1,$2-1,100+$3); } print "Now-Date = ", ctime($nowtime); print "Start-Date = ", ctime($sTime); $sleepSec = difftime($sTime,$nowtime); if ($sleepSec>0) { print "Want to sleep : $sleepSec seconds\n"; # sleep ($sleepSec); } else { print "Shit I missed my starttime...\n"; }

Replies are listed 'Best First'.
Re: Re: executing perl script at a certain time/day
by Biker (Priest) on Dec 06, 2002 at 08:24 UTC
      cool
      I did not know that this module exists.
      Than I would prefer to use the Schedule::ByClock module.
      (Why invent the wheel a second time ??)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://218003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-19 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found