Essentially, I want a script to run for as long as it takes, when the time is a certain time, I want the script to execute a command.
I just did it by going:
[tt]
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
while($min < 59 && $hour == 17){
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
if($min == 58) {print "Its almost 6 pm\n";last;}
}
print "done";[/tt]
and basically that's a simplified version, but if I run that at like 5:30, it will loop until 5:58 is reached, print that statement, and exit the loop.
This seems incredibly inefficient. First off, I like to avoid breaking out of a loop that way if possible, secondly, that will just loop several billion times waiting. Is there any way around this? for example can you get it to loop every 30 seconds or something? save CPU power...
I just did it by going:
[tt]
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
while($min < 59 && $hour == 17){
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
if($min == 58) {print "Its almost 6 pm\n";last;}
}
print "done";[/tt]
and basically that's a simplified version, but if I run that at like 5:30, it will loop until 5:58 is reached, print that statement, and exit the loop.
This seems incredibly inefficient. First off, I like to avoid breaking out of a loop that way if possible, secondly, that will just loop several billion times waiting. Is there any way around this? for example can you get it to loop every 30 seconds or something? save CPU power...