Link to home
Start Free TrialLog in
Avatar of everactive
everactive

asked on

Running cron job every 10 seconds

Hello,

Is it possible to run a cron job every 10 seconds?

Thanks.
Avatar of tripppr
tripppr
Flag of United States of America image

Ugly way to do it would be to create 6 lines in the crontab for each time you want the job to run, with each call passing an increment of 10 to the job (e.g:
* * * * *      /home/mylogin/somescript 0
* * * * *      /home/mylogin/somescript 10
* * * * *      /home/mylogin/somescript 20
* * * * *      /home/mylogin/somescript 30
.... etc
Then, your script would use the value passed to it and use the "sleep" command. (e.g:

#/bin/bash
sleep $1
.... rest of script follows
   
*/6 * * * * /path/to/script

That should work
nice.
wareb73's way is much cleaner.
No that should not work, that means every 6 minutes not a minute divided by 6

the only way you can do this is by enabling a time sleep under your script
Yes a far my understanding of cron u cannot run jobs every few secs without using help of sleep command inside the script
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
another way if it isn't a script is doing:

* * * * * /path/to/program
* * * * * /usr/bin/sleep 10 && /path/to/program
* * * * * /usr/bin/sleep 20 && /path/to/program
* * * * * /usr/bin/sleep 30 && /path/to/program
* * * * * /usr/bin/sleep 40 && /path/to/program
* * * * * /usr/bin/sleep 50 && /path/to/program

or if it's a script you do:

* * * * * /path/to/script

then you can have something like the following in the script:

I=0
while [ ${I} -le 50 ]; do
I=`/usr/bin/expr ${I} + 10`
/path/to/program
/usr/bin/sleep 10
done