Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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'
share|improve this answer
    
Thanks Eduardo, I really appreciate it. –  John Jun 3 '11 at 8:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.