Archive for the “Scripting” Category

Here is s snippet of code to check if a file exists so you don’t end up having your script run twice and edit the same file accidentally.

LOCK_FILE=/var/lock/`basename $0`
(set -C; : > $LOCK_FILE) 2> /dev/null
if [ $? != "0" ]; then
echo “Lock File exists – exiting”
exit 1
fi

### Place your script content here ###

trap ‘rm $LOCK_FILE’ EXIT

Comments 2 Comments »