LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-22-2012, 03:36 AM   #1
Winanjaya
Member
 
Registered: Sep 2003
Posts: 239

Rep: Reputation: 32
Question 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
 
Old 05-22-2012, 05:17 AM   #2
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by Winanjaya View Post
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.

Last edited by divyashree; 05-22-2012 at 05:33 AM.
 
Old 05-22-2012, 06:44 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,398

Rep: Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780
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.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 01:50 AM
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 02:37 PM
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 08:57 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration