LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to abort cron if the previous cron job not yet finished? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-abort-cron-if-the-previous-cron-job-not-yet-finished-946256/)

Winanjaya 05-22-2012 03:36 AM

how to abort cron if the previous cron job not yet finished?
 
Dear All,
I have a cron job that running every 5 minutes (*/5 * * * * dosomething)

how to abort cron if the previous cron job not yet finished?

please help

Thanks & Regards
Winanjaya

divyashree 05-22-2012 05:17 AM

Quote:

Originally Posted by Winanjaya (Post 4684575)
Dear All,
I have a cron job that running every 5 minutes (*/5 * * * * dosomething)

how to abort cron if the previous cron job not yet finished?

please help

Thanks & Regards
Winanjaya

You can abort execution of the dosomething.

In your dosomething script, you can add something like this,

When the dosomething starts , then it will create a lockfile somewhere and after finishing dosomething it will delete that lockfile.

Before creating the lockfile in dosomething, it will check whether that lockfile exists, and if exists then dosomething will exit without proceeding further.

ORR
Add this to you dosomething file.

Check the dosomething entry in your ps list , if running then it will simply exit without doing anything and if no entry in ps , then dosomthing will do its something.

chrism01 05-22-2012 06:44 PM

I recommend the latter approach in case the previous invocation fails without deleting the lock file ...
Alternately ( for something that is supposed to run that often) I usually make the actual prog into a daemon and then just put a watchdog into cron just to check for failures and/or do restarts.


All times are GMT -5. The time now is 12:33 AM.