Hands-on task
Don't let the script run twice
The script /usr/local/bin/job.sh runs on a schedule and sometimes starts before the previous run has finished — so the job runs in parallel with itself. Modify the script using a flock lock so that a second concurrent run exits immediately with a non-zero code without doing anything, while the first one keeps working. Leave the payload (writing a line to /var/lib/job/runs.log and the pause) as it is. Open the script in the Editor tab above the terminal: the /usr/local/bin directory is open there.
- flock
- locking
- file descriptors
- concurrent runs
- exec N>