Have cron wait for job to finish before re-launching
I have a开发者_JAVA技巧 cronjob that executes every second minute that usually runs in seconds, but sometimes for several minutes.
I need cron to not execute the command if it's already running when the next minute comes.
The line looks like this */1 * * * * cmd
I have tried with this * * * * * ID=job1 FREQ=1m AFTER=job1 cmd
but to no success.
Is it possible to solve with cron or do I have to implement locking?
You can make a temp file called inProgress (or whatever) and store it in a standard place, and use this to communicate to the next job if it should run or not.
What if flow of the job goes like this:
- Check for a standard inProgress file
- If it exists, quit
- Else, create inProgress file
- Do work
- Delete inProgress file.
精彩评论