Using flock in bash blocks

David Van Assche dvanassche at gmail.com
Thu Aug 7 05:13:09 EDT 2008


Well dont know if this helps but I was playing with dovecot recently,
and remember reading this:

# Locking method for index files. Alternatives are fcntl, flock and dotlock.
# Dotlocking uses some tricks which may create more disk I/O than other locking
# methods. NFS users: flock doesn't work, remember to change mmap_disable.
#lock_method = fcntl


On Thu, Aug 7, 2008 at 2:50 PM, Martin Langhoff
<martin.langhoff at gmail.com> wrote:
> 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
> _______________________________________________
> Devel mailing list
> Devel at lists.laptop.org
> http://lists.laptop.org/listinfo/devel
>



More information about the Devel mailing list