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');"
| [reply] [Watch: Dir/Any] |
Re: Timed Execution
by dws (Chancellor) on Nov 06, 2001 at 09:38 UTC
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
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. | [reply] [Watch: Dir/Any] |
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
| [reply] [Watch: Dir/Any] [d/l] |
|
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. :)
| [reply] [Watch: Dir/Any] [d/l] |
|
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
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
|
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.
| [reply] [Watch: Dir/Any] [d/l] |