There are a couple of programs that automate this feature, take away the annoyance and potential bugs from doing this yourself, and avoid the stale lock problem by using flock behind the scenes, too (which is a risk if you’re just using touch). I’ve used lockrun
and lckdo
in the past, but now there’s flock
(1) (in newish versions of util-linux) which is great. It’s really easy to use:
* * * * * /usr/bin/flock -n /tmp/fcj.lockfile /usr/local/bin/frequent_cron_job