Linux – Executing multiple commands with setlock

bashlinuxlocking

In a bash script I would like to execute multiple commands while keeping a file locked with setlock. Setlock however only supports the following usage:

setlock [-NnXx] [lock file] [command]

Is there a way to wrap multiple commands together besides using a separated script?

Best Answer

You can use sh as a command, enabling you to use &&, ; or || as usual to chain multiple commands as desired inside single quotes.

For example to run command1 followed by command2 (if the first exits without errors):

setlock lockfile sh -c 'command1 && command2'