back toc next

Using temporary files

#!/bin/sh

lockfile=/var/lock/foo.lock
tempfile=/tmp/foo-$$

#handle command line arguments here

if [ -f $lockfile ]; then
    exit 0;
fi

trap "rm -f $lockfile $tempfile" 0 1 2 3 15
touch $lockfile $tempfile || exit 1

#user program here