Yesterday wrote a requirement of the application script, according to the actual needs of the best can make it automatically every 3 seconds, but Crond seems to only support the points, how to do?
The first method:
Of course, the first thought is to write a trigger script that uses a dead loop in the trigger script to solve the problem, as follows:
Cat kick.sh
--------
#!/bin/bash
While:;d o
/home/somedir/scripts.sh 2>/dev/null &
Sleep 3
Done
-----------
Note Do not use Bash kick.sh & this way of running in the background for the first time, it will be zombie.
You can put it on a scheduled task to run it, and then delete this entry in the scheduled task. Finally put this script into/etc/rc.local so that it can be run every time it is powered on.
The second method:
Similar to the first method, but feels more convenient than the first.
Cat cron-seconds.sh
------------
#!/bin/bash
#For excuting The scripts every 3 seconds in Crond.
#20100124. WXG
For ((i=1;i<=20;i++));d o
/home/somedir/scripts.sh 2>/dev/null &
Sleep 3
Done
----------------
Then write the crontab every minute to execute, as follows
Crontab-e
--------
* * * * * */bin/bash/home/somedir/cron-seconds.sh
---------------
The third method:
So how do you use scheduled tasks to implement them directly?
The final solution is as follows, and it is verified that the script runs very stably.
Crontab-e
---------------------
# for Excuting scripts.sh every 3 seconds# #on 2010-01-22
* * * * * */home/somedir/scripts.sh
* * * * * * Sleep 3 &&/home/somedir/scripts.sh
* * * * * * Sleep 6 &&/home/somedir/scripts.sh
* * * * * * Sleep 9 &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep Wuyi &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
* * * * * * sleep &&/home/somedir/scripts.sh
#-----------------------------------------------------------------
If you think about it, you can understand the truth.
I'm still more inclined to use the third method. Because the first method and the second method is not strictly interval 3 seconds execution, will be greater than 3 seconds, because the execution of scripts.sh also takes a certain amount of time, even if the & symbol has been added to the background execution will also have some error. If the accuracy requirement is not high, the second method is recommended.
How to let Crond perform a task in seconds