Quick-and-dirty way to ensure only one instance of a shell script is running at a time

Use flock(1) to make an exclusive scoped lock a on file descriptor. This way you can even synchronize different parts of the script. #!/bin/bash ( # Wait for lock on /var/lock/.myscript.exclusivelock (fd 200) for 10 seconds flock -x -w 10 200 || exit 1 # Do stuff ) 200>/var/lock/.myscript.exclusivelock This ensures that code between ( …

Read more

What is the best way to ensure only one instance of a Bash script is running? [duplicate]

Advisory locking has been used for ages and it can be used in bash scripts. I prefer simple flock (from util-linux[-ng]) over lockfile (from procmail). And always remember about a trap on exit (sigspec == EXIT or 0, trapping specific signals is superfluous) in those scripts. In 2009 I released my lockable script boilerplate (originally …

Read more

Quick-and-dirty way to ensure only one instance of a shell script is running at a time

Use flock(1) to make an exclusive scoped lock a on file descriptor. This way you can even synchronize different parts of the script. #!/bin/bash ( # Wait for lock on /var/lock/.myscript.exclusivelock (fd 200) for 10 seconds flock -x -w 10 200 || exit 1 # Do stuff ) 200>/var/lock/.myscript.exclusivelock This ensures that code between ( …

Read more

Do I commit the package-lock.json file created by npm 5?

Yes, package-lock.json is intended to be checked into source control. If you’re using npm 5+, you may see this notice on the command line: created a lockfile as package-lock.json. You should commit this file. According to npm help package-lock.json: package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. …

Read more