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 ??)