I've used flock a lot in the past to ensure that a process only spawns once (in case it gets hung up/etc) but I've never used it for two different processes.
In this scenario two different scripts affect the same "temp" directory (the dir is clobbered at the start of each run). So I need to ensure the temp dir is not clobbered by one script while another one is still needing it.
My goal:
- Ensure 2 different scripts never execute alongside each other.
For example (cron sample):
0 * * * * flock -w 2 /tmp/lockfile.lock /some/script1.sh
2 * * * * flock -w 2 /tmp/lockfile.lock /another/script2.sh
Is this the correct way to isolate these two scripts from each other?