Use flock
. It’s new. It’s better.
Now you don’t have to write the code yourself. Check out more reasons here: https://serverfault.com/a/82863
/usr/bin/flock -n /tmp/my.lockfile /usr/local/bin/my_script
More Related Contents:
- How do I write a bash script to restart a process if it dies?
- Run a shell command when a file is added
- Managing log files created by cron jobs
- Why should eval be avoided in Bash, and what should I use instead?
- How to redirect output to a file and stdout
- How to kill a child process after a given timeout in Bash?
- ./configure : /bin/sh^M : bad interpreter [duplicate]
- The ‘eval’ command in Bash and its typical uses
- How to join multiple lines of file names into one with custom delimiter?
- Linux: copy and create destination dir if it does not exist
- How to redirect the output of the time command to a file in Linux?
- How to handle more than 10 parameters in shell
- crontab PATH and USER
- How to count lines in a document? [closed]
- Changing default shell in Linux [closed]
- Linux Script to check if process is running and act on the result
- Redirecting command output in docker
- When to wrap quotes around a shell variable?
- How to get file creation date/time in Bash/Debian?
- Disable and re-enable address space layout randomization only for myself
- How to join multiple lines of filenames into one with custom delimiter
- Check if a variable exists in a list in Bash
- Doesn’t sh support process substitution
- Get yesterday’s date in bash on Linux, DST-safe
- Alias with variable in bash [duplicate]
- find a pattern in files and rename them [closed]
- Linux shell script to add leading zeros to file names
- Need to remove the count from the output when using “uniq -c” command
- Negate if condition in bash script
- Changing environment variable of a running process