What is the simplest/best way to ensure only one instance of a given script is running - assuming it's Bash on Linux?
At the moment I'm doing:
ps -C script.name.sh > /dev/null 2>&1 || ./script.name.sh
but it has several issues:
- it puts the check outside of script
- it doesn't let me run the same script from separate accounts - which I would like sometimes.
-Cchecks only first 14 characters of process name
Of course, I can write my own pidfile handling, but I sense that there should be a simple way to do it.