Reputation: 3261
Hi I have a shell script which calls another script and I have locking mechanism inside main script.
Please check below code.
Does this mean that other script(/home/user/anotherscript.sh) will not be called and executed as long as script is locked by locking mechanism.
function funcexit() {
echo "Locked"
exit 1
}
(
flock -x -w 10 549 || funcexit
bash /home/user/anotherscript.sh
do some stuff
)
Please let me know the thougts...
Upvotes: 0
Views: 98
Reputation: 2151
The script line flock -x -w 10 549 || funcexit
says: "try to get an exlusive lock on fd# 549, with maximum waiting time of 10 seconds, if successfully acquire the lock, continue with the next line, otherwise call function funcexit
" thus, if the script can not acquire the lock in 10 seconds, funcexit
will be called (thus exit).
Upvotes: 2