2004-08-27 01:48

by Vasil Kolev

Nice, quiet day… I fixed some small stuff, and again found out that all scripts that are ran from crontab must check for an already running their copy… Here’s a template for such scripts:

#!/bin/sh
#the script's uniqe name
name=SCRIPTNAME

if [ -f /var/run/$name.pid ]; then
        if [ -d /proc/`cat /var/run/$name.pid` ] ; then
                echo $name.sh already running!
                exit 0
        fi
fi

echo $$ > /var/run/$name.pid
trap "rm -f /var/run/$name.pid" exit SIGHUP SIGINT SIGTERM 

#do some stuff
echo Ugabugabuga
#cleanup
rm -f /var/run/$name.pid

In the moment I’m sure that it works under linux, because I use /proc, to check if the pid of the process is still valid, it will work on all unixes, that have such semantics.

In the evening me and Velin watched “Conspiracy Theory”, after which I went out for a walk, because most of the day I had stayed at home… The walk through the center of Sofia in 1:00 is a pleasant one, not a lot of people around, but I was sweating a lot, it was still hot… When is the autumn coming…

Leave a Reply