On 5/11/20 5:35 PM, Samuel Sieb wrote:
On 5/11/20 2:13 PM, Robert Moskowitz wrote:
> I found
https://www.putorius.net/lock-files-bash-scripts.html, and
> part of it is not making sense to me.
>
> The following is suppose to be an example of making a script waiting
> indefinitely for the an earlier instance to complete:
>
> #!/bin/bash
> exec 100>/var/tmp/testlock.lock || exit 1
> flock 100 || exit 1
>
> echo "Doing some stuff…"
> echo "Sleeping for 30 seconds…"
> sleep 30
>
> I get the exec line's exit 1: If you can't get the file descriptor,
> something is wrong and exit.
>
> But the next line does not make sense. If you can't lock exit? How
> is that indefinite?
No, that is if the flock command throws an error, then exit.
Otherwise, it waits forever until it can lock the file.
Ah, now it makes sense.
thanks