Re: OT. Cron jobs



On 3/10/07, Mike Blezien <mickalo@xxxxxxxxxxxxxxx> wrote:
Hello,

Sorry for the OT question, but couldn't find the info I was looking for and
thought could get a quick answer from the list.

We have a perl script that needs to run 4 times a minute. Can this be done via
cron or is there an easier way to do this within the Perl script itself? This 4
times a minute every day.

Cron can only handle a resolution of one minute, but you can use sleep
along with four jobs to achieve the effect you desire:

cowens@putain:~$ crontab -l
* * * * * echo -n "1:" >> /home/cowens/log.txt; date >> /home/cowens/log.txt
* * * * * sleep 15; echo -n "2:" >> /home/cowens/log.txt; date >>
/home/cowens/log.txt
* * * * * sleep 30; echo -n "3:" >> /home/cowens/log.txt; date >>
/home/cowens/log.txt
* * * * * sleep 45; echo -n "4:" >> /home/cowens/log.txt; date >>
/home/cowens/log.txt
cowens@putain:~$ tail -f log.txt
1:Sat Mar 10 21:17:01 EST 2007
2:Sat Mar 10 21:17:16 EST 2007
3:Sat Mar 10 21:17:31 EST 2007
4:Sat Mar 10 21:17:46 EST 2007
1:Sat Mar 10 21:18:01 EST 2007
2:Sat Mar 10 21:18:16 EST 2007

This is still not an ideal solution though, since two copies of a
script can be running concurrently if the script takes more than 15
seconds to run. For some scripts this is not an issue, but others
have issues with that. In those cases a better scheduler than cron is
required. You could also change the script into a daemon.
.