Have you ever had your server drown in processes because a cronjob you wanted to run every minute suddenly never finished, and you ended up having multiple instances of your nice script going at the same time? I have! A quick and easy solution to this problem, was this wrapper-script that I created a while back. Basically, it’s just some pid-file processing before your own code starts, to make sure only to run a single instance of the script at a time. With this you’ll avoid having your scripts pile up again.

The script: cron-shell-script-template.sh
The config: cron-shell-script-template.conf-sample

If you find this script useful, or have some improvements, feel free to drop me a comment below. Thanks!


The script had a little bug, which caused two instances of the script to be started under some circumstances. The script behind the link above has been updated to correct this.

Update, July 23.:

I’ve removed the PIDDIR-setting from the actual script, and moved it to a separate configuration-file. It’s all generic, the conf-file is expected to be named the same as the script with the last “.ending” replace with “.conf”. The point of this is to be able to e.g. keep the script itself in a repository (like subversion) and keep the config separate so you can update the script from the repository without having local changes to worry about.