views:

267

answers:

1

Hello experts. I'm currently using Capistrano to deploy my web application which works like a charm.

In my new project I must execute a command from sudo /bin/bash shell.

Is it possible for Capistrano to login to the machine as user X, run sudo /bin/bash, enter the password and then execute a command in the sudo shell? If yes, could you please provived me with an example.

With regards

jakob

+1  A: 

Is there a specific reason you need to be in a root shell rather than executing the command with sudo? If executing a command with sudo, you can simply sudo 'command' instead of run 'command'.

I did a little experimentation to try to get a root shell with capistrano without logging into the server directly as root, and wasn't able to make much progress.

If running with sudo won't work, please update your question to let us know why and maybe we can help you find a workaround for it.

Update:

After playing around a little more, I found that you can execute an individual command (or string of commands) in a root shell by doing something like sudo '/bin/bash -c "whoami"'. It's getting an interactive root shell that's tricky.

Emily
All you need to do to get a root shell with sudo is `sudo -s`. Kids these days...
Justin
Capistrano shell has (or at least had) problems with interactive commands run within the initial shell. Did you try that and get it to work?
Emily