1

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.

8
  • 3
    why are you assigning the whole su command chain to a variable? You'll have to use eval "$DAEMON" to get it to work, and everyone hates evaling code, (its a big security risk). Good luck. Commented Feb 19, 2012 at 18:38
  • It was the first thing I thought of when I noticed I have to run this init script as the user 'deployer'. Better ways to do it are welcome. Commented Feb 19, 2012 at 19:25
  • 3
    Why is the command in a variable? The implicit suggestion here for a better solution is to not put the command in a variable. See also mywiki.wooledge.org/BashFAQ/050 Commented Feb 19, 2012 at 20:01
  • @tripleee Ah. I didn't get it. Good idea! In fact, that link right there is what I needed to read all along but never found on my own. Write your comment as an answer and I'll accept it. Commented Feb 20, 2012 at 9:22
  • @shellter deserves the credit here really. Glad I could help clarify his (?) point, though. Commented Feb 20, 2012 at 13:10

2 Answers 2

2

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"'
Sign up to request clarification or add additional context in comments.

Comments

1

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"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.