Is it possible to run a cron job every 30 seconds without a sleep command?
|
|
If your task needs to run that frequently, cron is the wrong tool. Aside from the fact that it simply won't launch jobs that frequently, you also risk some serious problems if the job takes longer to run than the interval between launches. Rewrite your task to daemonize and run persistently, then launch it from cron if necessary (while making sure that it won't relaunch if it's already running). |
|||||
|
|
Cron is designed to wake up at every minute, so it is not possible to do it without some hacking, for example sleep like you mentioned. |
|||
|
|
|
Candidate for the most creative misuse of a Linux command:
If
then
indicating a pretty good level of precision. |
|||||
|
|
I'd have a couple of concerns: (1) sometimes a system gets busy and cannot start things exactly on the 30 second point, it is then possible that at the same time you are running one job another job would pop and then you have 2 (or more) jobs doing the same thing. Depending on the script, there may be some significant interference here. Thus, coding in such a script should contain some code to insure that only one instance of the given scripting is running at the same time. (2) The script could possibly have a lot of overhead, and consume more system resources than you might want. This is true if you are competing against a lot of other system activities. Thus as one poster has put it, in this case I'd seriously consider putting in a daemon running with additional processes to ensure it remains running if its of critical importance to your operations. |
|||
|
|
Don't forget to write something into your program so that it exits if a previous instance is already running.
Of course, this still leaves a very small opportunity for failure, so search google for a better solution applicable to your environment. |
|||
|
|