What\'s a quick-and-dirty way to make sure that only one instance of a shell script is running at a given time?
I wanted to do away with lockfiles, lockdirs, special locking programs and even pidof
since it isn't found on all Linux installations. Also wanted to have the simplest code possible (or at least as few lines as possible). Simplest if
statement, in one line:
if [[ $(ps axf | awk -v pid=$$ '$1!=pid && $6~/'$(basename $0)'/{print $1}') ]]; then echo "Already running"; exit; fi