Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to do every minute, but how about every 10 seconds?

share|improve this question

migrated from Mar 11 '11 at 3:54

This question came from our site for professional and enthusiast programmers.

up vote 6 down vote accepted

You can't schedule the job every ten seconds, but I suppose you could schedule the job to run every minute, and sleep in a loop in 10s intervals. This would be predicated on your command being completed before the ten second interval expires, or you'll get overlap when the next command runs. This feels like a precarious solution, but if you can guarantee very short execution of the main command of the script, it would work.


while [ $i -lt 6 ]; do
  /run/your/command &
  sleep 10
  i=$(( i + 1 ))
share|improve this answer
Hi Michael. You're putting 10 second gaps between executions of the command. Say the command takes 8 seconds, then you'd start the second execution after 18, the third after 36, fourth at 54 - and it would still be running when the cron job kicked off another copy. If you put an ampersand (&) after /run/your/command it will be executed in the background which avoids this problem. – Tony Mar 10 '11 at 3:22
@Tony good catch. Edited. – Michael Mar 10 '11 at 3:32
I do a similar thing... I just use *'s in crontab, and then my script uses flock and loops forever, never quits unless it can't obtain a lock. – Peter Mar 5 at 12:53

I had a similar task last week. My solutions was to multiply the standard cron entries to the desired frequency. My crontab looks like:

* * * * * /usr/local/bin/php /var/www/myscript.php
* * * * * sleep 10; /usr/local/bin/php /var/www/myscript.php
* * * * * sleep 20; /usr/local/bin/php /var/www/myscript.php
* * * * * sleep 30; /usr/local/bin/php /var/www/myscript.php
* * * * * sleep 40; /usr/local/bin/php /var/www/myscript.php
* * * * * sleep 50; /usr/local/bin/php /var/www/myscript.php

If you want to check results of myscript.php, e.g. for debugging, just append

&> /tmp/myscipt.log

to each line in the crontab above. Then stderr and stdout get redirected to the log file.

share|improve this answer

Take a look at this forum post where the solution is discussed :

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.