flock

flock: how to run several commands?

-c, --command command
Pass a single command to the shell with -c.

With a single command, we have:

flock --exclusive --timeout 5 mylockfile.txt --command myscript.sh

But how to pass several commands?

Invoke the default shell (sh) or a specific shell (e.g. bash) explicitly:

flock --exclusive --timeout 5 mylockfile.txt --command sh -c 'myscript1.sh; myscript2.sh; myscript3.sh'

Variables changed within the command are local to the shell instance.

flock

flock = file lock, use a file as a locking mechanism to prevent several instances of the same script from running concurrently.

Syndicate content