Using flock in bash blocks

Martin Langhoff martin.langhoff at gmail.com
Thu Aug 7 05:05:17 EDT 2008


Advanced bash/shell scripting question - I cannot seem to do the
correct incantation with /usr/bin/flock to make it work in a bash
block. Can any Master of the Bash give me a hint?

In other words, I am trying to put into to use the example in man
flock, where it says:'second form is convenient inside shell scripts'.


 # this does what I expect, and if I attempt
 # to obtain a second lock it fails
 $ flock -n /tmp/lockmyprecious sleep 60

 # this does not seem to work
 $ (flock -n 200; echo gotlock; sleep 60)200>/tmp/lockmyprecious

There is a bash script where I want to wrap a lock around a large-ish
code block that I don't want to split off to a separate script.

hints?


m
-- 
 martin.langhoff at gmail.com
 martin at laptop.org -- School Server Architect
 - ask interesting questions
 - don't get distracted with shiny stuff - working code first
 - http://wiki.laptop.org/go/User:Martinlanghoff



More information about the Devel mailing list