Stop cronjobs overlapping ?
Hi folks,
Is there any way I can stop my cronjobs overlapping ? I have shell scripts called from crontab which rsnap/rsync all the data from my remote servers to a main backup server. One remote server (of 7) is backed up each night plus another backed up every morning. I've come in this morning to find that last night's has not yet completed and this morning's has already started.... so the network is too busy for some staff to work :-( Is there a way I can tell crontab to not start a job until a running job has completed ? TIA Mike |
At the very beginning of the morning job you can check if the night job is still running and wait for its completion before proceeding. A way to do this can be
Code:
while ps -C night_job_name > /dev/null |
Excellent, I think I can manage that OK. Many thanks.
|
You could create a lock file in /tmp at the start of the first cron job, and remove it at the end, and have the second cron job check to see if this lock file exists.
Dave |
If they are dependent jobs, use the lock file, otherwise use the ps solution.
Reasons: if dependent, you don't want the 2nd job to run even if the 1st one crashes (lock file is not removed). If you only need them to not overlap in time (as seems to be the case here),the 2nd job should still run, even if the first one crashes, ie so long as the 1st one is not actively running... |
Ah, thanks for that tip Chris. At the moment the scripts are not dependent so I'll use the ps method. At some time in the near future I am planning to modify them - run the rsync script and when completed tar entire backup directory and move to an archive. When I start using that I will probably need to employ lock file method.
ATB Mike |
The other option for that is for script1 to call script2 as its last cmd ...
|
All times are GMT -5. The time now is 08:18 PM. |