On Thu, May 24, 2012 at 12:01 AM, Craig A. Adams <crai...@iafrica.com> wrote:
> Thank you for the help rbmj.
>
>
> On 23/05/2012 19:02 PM, rbmj wrote:
>>
>> a lock, in this case). It then exits the subshell (the section
>> surrounded by () parens).
>
>
> What is the effect of exit codes in the script code section? Does an exit
> 0(1,2...) exit just the subshell or the entire script? I am worried by a
> lock being left in place by one of these.
>
>
>> The > redirector is redirecting file descriptor 200 to the file you are
>> specifying. In this case, I think that the choice of 200 is arbitrary.
>> As long as you redirect the same file descriptor that you pass to flock,
>> then the number shouldn't matter (though don't choose stdout :D)
>
>
> So it is not actually creating the lock file? So I must make sure the lock
> file exists in advance?
>

If you use the N> FILENAME syntax, the shell will create the file and
make descriptor N refer to the named file.  You don't have to create
the file yourself.  Details of this kind of redirection are in the
bash manual, if you're interested.

Understanding this kind of usage of flock requires an understanding of
the inheritance of descriptors from parent process to child process.
It is by no means complicated, but we might be getting rather
off-topic here.

For your immediate needs, you can use one of the other forms of the
flock command.

Just replace your backup command:

 /script/backup arg1 arg2

with:

 flock -xn /tmp/backup-lock /script/backup arg1 arg2

Don't worry about locks being left behind.  When your backup script
ends, the flock command also ends, releasing its lock on
/tmp/backup-lock.  The file is automatically created the first time,
but will not be deleted.  It's a 0-byte file, so this should not be
terribly worrisome.

-- 
regards,
kushal


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAH8GtdNqNJDEg20dUHy0vr5HrkpDym3u7GszAv9=vz0r+2r...@mail.gmail.com

Reply via email to