Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Timed Execution

by Anonymous Monk
on Nov 06, 2001 at 09:16 UTC ( [id://123511]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to execute one of my scripts at a specific time (11:00 in the morning to be exact) on a daily basis. Is there any easy way to automatically do this?
Do I have to write a script that would track the time and then call this other script? The only downside would be that the time-tracking script would have to running full-time.
Thanks for any insights.

Replies are listed 'Best First'.
Re: Timed Execution
by maverick (Curate) on Nov 06, 2001 at 09:25 UTC
    If you're on a Unix system of some sort and have permission. 'cron' (man cron) would be the way to go, as it was designed exactly for this task.

    If you're on a Windows box, they have a cron like 'Scheduler' that should server the same function.

    HTH

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

Re: Timed Execution
by dws (Chancellor) on Nov 06, 2001 at 09:38 UTC
    On NT/Win2K, you might be able to use 'at', which is a pale imitation of chron. You may need to install the Scheduling Service to get it.

    Note that jobs scheduled via at will unschedule themselves if they run with errors.

Re: Timed Execution
by joealba (Hermit) on Nov 06, 2001 at 09:26 UTC
    If it is UNIX, use cron.

    If it's Windows, umm... uhh.. anyone? Updated: Maverick says use the Task Scheduler. Has anyone ever actually used it before?

    If it's Macintosh, just speak your request into the microphone.
Re: Timed Execution
by slayven (Pilgrim) on Nov 06, 2001 at 09:54 UTC
    a quick hack would be something like this:
    do { sleep(1); } until ( (localtime(time))[2] == 11 && (localtime(time))[1] == 0 );

    this snippet added to the top of your script will loop until 11:00 and continue executing your script.
    note that this is just a workaround! you really should use cron or something similar if you're stuck to windows.

    -- slayven
      Cool, but that'll only work once, and it'll waste LOTS of cpu cycles. How about this:
      while (1) { sleep(50); # If it's a windows box, give yourself a little extra time. Trust me. + my ($min, $hour) = (localtime(time))[1,2]; if ($hour == 11 && $min == 0) { # Do your 11:00 stuff } }
      Note that cron is the right answer. We're just having some fun. :)
        actually, i've chosen sleep(1) to match 11:00:00 :)
        you're right, it will waste lots of cpu cycles, but i've been playing with idletime a while ago, because 1 second was way to much to wait for that application. i found that on my cpu (it was an AMD K6-2 300) 0.1 second was the time, that doesn't hurt the cpu at all (select(undef, undef, undef, 0.1)).
        since then i'm rather unconscionable using sleep ;)

        -- slayven
      Just remember that when you want to run such a script in the background, you need at least a $SIG{'INT'} = 'IGNORE'. Look at perldoc perlvar and/or take a peek here, which actually is my first node at this place.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found