[clue-tech] cron jobs off to the races

chris fedde chris at fedde.us
Sat Jan 2 09:56:18 MST 2010


On Tue, Dec 29, 2009 at 1:05 PM, David L. Willson <DLWillson at thegeek.nu> wrote:
> Is there a way to tell cron to automatically check to see if a job is already running before invoking it?  It seems a bit silly to have to implement "prior invocation detection" code in every cron-invoked script.  Doesn't it?

Upstart and initab have features to monitor existing processes.  But
classic crond does not.

I guess I've accepted the need to implement "prior invocation
detection".  This is my backup script that uses an exclusion technique
I reuse frequently.

#!/bin/sh
#set -x

level=`date +%w`
host=`hostname`
pidfile=/tmp/backup.pid
dumpdir=/net/dvclnas1/vol/exports/ocv/dump

# exclusion
if test -f $pid
then
    pid=`cat $pidfile`
    if kill -0 $pid
    then
        echo $0 running as $pid > STDERR
        exit 1
    fi
fi
echo $$ > $pidfile

dump -${level}uf $dumpdir/$host.slash.$level.dump /


More information about the clue-tech mailing list