Emil Ahlbäck
Emil Ahlbäck

Reputation: 6206

Bash scripting and escaping

I'm having some trouble with this bash script, which I intend to use as a startup script for a web server running nginx+unicorn.

DAEMON='/bin/su - deployer -c "/home/deployer/.rvm/gems/ruby-1.9.3-p125/bin/unicorn -c /home/deployer/apps/myapp/current/config/unicorn.rb -E production -D"'

Error:

/bin/su: invalid option -- 'E'

I need to run the script as the user deployer, but I am uncertain how to pass all my command to /bin/su. I'm sure this is a simple escaping error but after trying several different ways of escaping it but I am just not getting this right. Thanks.

Upvotes: 1

Views: 1272

Answers (2)

l0b0
l0b0

Reputation: 58768

There are no variables in the command, so you can simply put it in a function:

daemon() {
    /bin/su - deployer -c "/home/deployer/.rvm/gems/ruby-1.9.3-p125/bin/unicorn -c /home/deployer/apps/myapp/current/config/unicorn.rb -E production -D"
}

Upvotes: 1

David Costa
David Costa

Reputation: 1808

Try to separate sudo options and command with --

DAEMON='/bin/su - deployer -c -- "/home/deployer/.rvm/gems/ruby-1.9.3-p125/bin/unicorn -c /home/deployer/apps/myapp/current/config/unicorn.rb -E production -D"'

Upvotes: 2

Related Questions