Home » Infrastructure » Unix » How to avoid duplication of Cron Jobs
How to avoid duplication of Cron Jobs [message #207955] Thu, 07 December 2006 08:43 Go to next message
A Ikramur Rahman
Messages: 81
Registered: May 2004
Member
We have a UNIX script which has been scheduled to run every 15 minutes. Sometime, the UNIX cron job takes more than 15 minutes to finish and by the time it finishes the next schedule already starts running. This results in duplication of data. This does not occur regularly, but when the server is slow or there are more data to process, we face this problem.

We can’t increase the frequency of job as this is very critical.

Is there any way, we can check whether the UNIX cron job is finished or not and if it is not finished we can hold the next schedule?
Re: How to avoid duplication of Cron Jobs [message #207961 is a reply to message #207955] Thu, 07 December 2006 09:00 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10672
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Make the script a little smarter.
Write a log file to OS with some status. Something like this
Inside your script
Check the status.
If DONE 
then start the business.
     update the logfile with status = BUSY
     after the business is done update the lofile status= DONE
Else do nothing and exit.


This is just a simple method.
You can get any fancy with some real scripting here.

[Updated on: Thu, 07 December 2006 09:01]

Report message to a moderator

Re: How to avoid duplication of Cron Jobs [message #207966 is a reply to message #207955] Thu, 07 December 2006 09:22 Go to previous messageGo to next message
scorpio_biker
Messages: 154
Registered: November 2005
Location: Kent, England
Senior Member
Hi,

We have a job that checks whether an overnight job is still running and then loops until its finished. It just emails certain people once the job is complete but I'm sure you could use something similar.

   PROC_COUNT=`ps -ef | grep <prog_name> | wc -l'`
   while [ $PROC_COUNT -gt 1 ]
   do
      sleep 240
      PROC_COUNT=`ps -ef | grep <prog_name> | wc -l'`
   done

   <start your job here>
Re: How to avoid duplication of Cron Jobs [message #208116 is a reply to message #207955] Fri, 08 December 2006 04:26 Go to previous message
A Ikramur Rahman
Messages: 81
Registered: May 2004
Member
Thanks for your ideas and solutions. This really helped.
Previous Topic: Needs Help
Next Topic: Comparing contents of a file with data in database
Goto Forum:
  


Current Time: Tue Dec 06 06:33:17 CST 2016

Total time taken to generate the page: 0.15885 seconds