LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-22-2008, 05:13 AM   #1
MikeAtVillage
Member
 
Registered: May 2005
Location: Mid Wales (UK)
Distribution: Slackware 8.0, Suse 10.0/1/2, CentOS (SMEServer7)
Posts: 38

Rep: Reputation: 15
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
 
Old 05-22-2008, 05:59 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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
do
    sleep 300
done
where night_job_name is the name of the script launched by the night cronjob.
 
1 members found this post helpful.
Old 05-22-2008, 06:16 AM   #3
MikeAtVillage
Member
 
Registered: May 2005
Location: Mid Wales (UK)
Distribution: Slackware 8.0, Suse 10.0/1/2, CentOS (SMEServer7)
Posts: 38

Original Poster
Rep: Reputation: 15
Excellent, I think I can manage that OK. Many thanks.
 
Old 05-22-2008, 07:15 AM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
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
 
Old 05-22-2008, 08:33 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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...
 
Old 05-23-2008, 12:48 AM   #6
MikeAtVillage
Member
 
Registered: May 2005
Location: Mid Wales (UK)
Distribution: Slackware 8.0, Suse 10.0/1/2, CentOS (SMEServer7)
Posts: 38

Original Poster
Rep: Reputation: 15
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
 
Old 05-23-2008, 01:08 AM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
The other option for that is for script1 to call script2 as its last cmd ...
 
  


Reply

Tags
cronjob, crontab


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
some cronjobs don't work xpucto Linux - Newbie 5 05-05-2008 06:25 AM
cronjobs stop working after expiration of root password nichu Linux - General 1 09-28-2007 03:30 AM
partition overlapping w-mar Linux - Enterprise 3 02-13-2007 10:55 AM
Problem with cronjobs..... freakin'me Linux - General 7 02-11-2006 03:08 PM
is there a way to stop cronjobs mail for certain acticities manojthakkar Linux - General 5 12-08-2003 10:56 PM


All times are GMT -5. The time now is 11:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration