So I have a bash scripts that does some things (pull from github, delete folders .. etc ..) pretty basic stuff. I usually run it whenever I need a new version of the web app on the server.The thing is there isn't anything that stopping this script from running simultaneously by different people (almost all developers connect to this server and they execute the same command).So far, it didn't happen that the script is run by more than 1 developer at a time.How do I make sure that this script cannot be run if it's already running by another user? Folder locking or checking if the script is running by another user (is this doable?) something else? All users that can run this script are sudoers.EDIT: Well after checking my colleagues turns out that not all of them are using the script .. some of them are executing the commands by hand so I need to lock the folder itself.
How do I make sure that a script is run exclusively?
bash script
flock - Manages locks from shell scriptsman flockeg flock -x lockfile -c command