at the beginning of your script, create a unique temp file somewhere in the file system if the file no longer exists, in which case your script is already running, and you should exit. at the end of your script, delete the unique temp file.
There are other options for this, I'm sure, but they all have a similar idea. if you like this answer, check the box next to it. thank!
source
share