[clue-tech] cron jobs off to the races

David L. Anselmi anselmi at anselmi.us
Sun Jan 3 19:35:56 MST 2010


chris fedde wrote:
> 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

kill -0 will fail to notice PIDs that belong to other users, unless run as root.  That might be 
"good enough" or might not.

Using a static file name means this script can't be run simultaneously even by other users (maybe 
not a problem here but I've run into this many times).

Dave


More information about the clue-tech mailing list