This script is taken from Quick and Dirty way to ensure only one instance of a shell script is running at a time
For example, this can be used to ensure SAGE Mirroring rsync run once.
# rsyncs from sage.math.washington.edu using its rsync daemon # for automated use, remove the "vv" and "progress" switches # locking mechanism from # http://stackoverflow.com/questions/185451/quick-and-dirty-way-to-ensure-only-one-instance-of-a-shell-script-is-running-at-a LOCKFILE=./rsync_sagemath.lock if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then echo "rsync_sagemath already running ... exit" exit fi # make sure the lockfile is removed when we exit and then claim it trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT echo $$ > ${LOCKFILE} rsync -av --delete-after rsync.sagemath.org::sage /var/www/html/sage rm -f ${LOCKFILE}