[RndTbl] Potentially long cron jobs

Trevor Cordes trevor at tecnopolis.ca
Thu Apr 1 17:46:11 CDT 2010

On 2010-04-01 Kevin McGregor wrote:
> I want to run something via cron which will take anywhere from less
> than a minute to a day or so (possibly). Most of the time it will be
> well under an hour, and I'd like it to run hourly, except if it's
> still running, in which case nothing more need be done.

To not worry about races, and still keep things simple:

lockfile -r 0 -l 86400 $lock >/dev/null 2>&1 || exit
rm -f $lock

see man lockfile

may not be terribly portable beyond linux(?)

Play with the -l option or omit it.  For your case you'd want to set it
to the absolute max secs it could possibly take your program to run.

Perl also has a ways to do locking.

Note: "Lockfile is NFS-resistant": I have no idea what they mean by
that, will it work or not?  Pretty nifty if they have it working on
NFSvX where X<4.

More information about the Roundtable mailing list