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";
}
|