bash locking in script

Bash locking Intro Once in a while i want to start a bash script and make sure it one at a time. So searching for solution for creating a lock file in bash, you want to have a solution that doesn’t create a race condition. Explanation Start defining which lockfile you want to use export lockfile=/tmp/lockfile.txt Get pid from lockfile, return empty string if file doesn’t exists or is empty For added protection removed character from the file that isn’t a number
3 minutes to read

bash debugging tricks i forget all the time

Bash debugging Introduction Once in a while i need to debug a bash script that i wrote, but i need to search how to get the line number of debug to a file, so easier for me to put it in mij blog, maybe it will help somebody else also. Howto Enable debugging set -x Add line numbers PS4=’$LINENO: ' Debug to external file exec 5> debug_output.txt BASH_XTRACEFD="5" PS4='$LINENO: ' set -x Disable debug
One minute to read