Let's understand our script in detail:
- The mylock.sh script reuses a couple of concepts that we are already familiar with: traps and symbolic links. We know that if a trap is called or rather, it catches a particular signal, it can clean up a lock file (as is the case in this script). Symbolic links are used since they can survive atomic operations over network file systems. If a file is present at the LOCKFILE location, then a lock is present. If the LOCKFILE is absent, the doors are open.
- When we run mylock.sh, we will get the following because no lock file exists yet—including any temporary ones:
$ bash mylock.shCreated tmp lockDoor was left unlocked
- Since the preceding script exited correctly, the SIGKILL signal was ...