Re: Pause Loop
by shigetsu (Hermit) on Apr 27, 2007 at 23:47 UTC
|
Have you considered using a cronjob instead?
Then the loop would become superfluous and you could make it run the entire script without a stop.
| [reply] |
Re: Pause Loop
by syphilis (Archbishop) on Apr 27, 2007 at 23:58 UTC
|
while(1)
{
#script line 1
#script line 2
#script line 3
#script line 4
sleep (3600);
}
See "perldoc -f sleep".
Cheers, Rob | [reply] [d/l] |
|
|
It seems that the sleep command will total all the commands there, i tried
while(1)
{
print 1;
sleep (1);
}
And nothing displayed.
Thanks for the looping part though :) | [reply] [d/l] |
|
|
$| = 1;
before the loop to turn off buffering.
| [reply] [d/l] |
Re: Pause Loop
by BrowserUk (Patriarch) on Apr 28, 2007 at 05:51 UTC
|
How accurate do you want the delay to be? If you embed a 1 hour delay in the loop along with the commands that are being run, your script will run every 1 hour + however long the commands take, so your schedule will slip continuously. A slightly different formulation of the loop will account for that without having to accurately time how long the commands take:
my $endTime = time() + 3600;
while( 1 ) {
# Do stuff,
# Do more stuff
# And more
# And more
# And more
# And more
sleep 1 while time() < $endtime;
$endtime = time() + 3600;
}
The inner sleep loop will consume negligible cpu but will ensure that you don't sleep longer than you need to, even if the active part of the script varies in how long it takes to run.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
|
|
while (1) {
my $start_time = time();
## do stuff here
sleep 3600 - time() + $start_time;
}
| [reply] [d/l] |
|
|
while (1) {
# Do stuff here;
my $next = int((time + 3599)/3600) * 3600;
sleep ($next - time);
}
| [reply] [d/l] |
|
|
| [reply] |
|
|
|
|
Re: Pause Loop
by thezip (Vicar) on Apr 27, 2007 at 23:53 UTC
|
pyro.699, what is your OS? If you're on one of the Unices, why not just have the crond handle it? This would have the benefit of not having to poll constantly ...
Where do you want *them* to go today?
| [reply] |
|
|
I would use cronjobs except the script will be moving from pc to pc and will not be stationary. Some are Windows XP others Are Ubuntu Linux, it would just be easier if it had a nevereding loop :)
Thanks though
| [reply] |
|
|
Given the assumption that you'll need to poll, you could use something like MIME::Lite to send email in an OS agnostic manner...
Update:
This probably isn't such a good solution since MIME::Lite is not core Perl and you'd need to install it on each target machine.
Nonetheless, you'll have difficulties getting the email part to work due to OS differences...
What is your plan of attack for this?
Where do you want *them* to go today?
| [reply] |
|
|
|
|
Re: Pause Loop
by fmerges (Chaplain) on Apr 29, 2007 at 20:40 UTC
|
Hi,
you can do it using the time and sleep but you can also take a look at Schedule::Cron can be useful in the future once it extends or you want to do more fancier stuff.
Regards,
fmerges at irc.freenode.net
| [reply] |