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

In reply to Re: executing perl script at a certain time/day by Chief of Chaos
in thread executing perl script at a certain time/day by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.