Great article, but a common scenario is missing: I want to run a long running script, but not if another copy of it is already running.
https://linux.die.net/man/1/flock would probably help
if ! mkdir .lock; then
printf >&2 "Already running?\\n"
exit 1
fi
Some network file system implementation do not guarantee atomic mkdir, so you still need an extra caution with this method.