I am currently writing a script that runs continually, but only actually does something every two minutes. I had previously achieved this by doing this:
while()
{
...code...
sleep(120);
}
However, the sleep function has become a terrible labryinth of problems to my script and I would like to find a more efficient way to run my script continually than with a while loop and a sleep function. Any suggestions? Oh and this is on a Win32 platform.
This is what the script does essentially. It automates an rsync backup of files betwen two servers every two minutes. The problem I was having with sleep is that it delays any print/output file statements until after the sleep has executed, and this often resulted in output files getting truncated.
for example if i did this:
print "hello";
sleep(120);
The script would wait two minutes before printing out hello. Very strange problem and i don't know how to fix it, maybe you guys do?