I have a number of centralized scripts, which install certain pieces of middleware (for example JBoss-AS, JBoss-EWS, etc). The idea is to use expect to write a script which runs the script (which can contain serveral commands and if ... then ... else, as well as loop structures) on another server, under an other user.

What I need is an expect script which executes something like this:

central $ ssh <user>@<remote> "sudo local-script"

I have tried to pipe things in like cat local-script | ssh -t <user>@<remote> sudo, but sudo won't allow this. When I get the above sequence, i.e. run sudo local-script through a ssh channel, then I can use autoexpect to generate an expect file which works (also things like ssh -t <user>@<remote> sudo < cat local-script doesn't work.

I know you can use this to run commands that are on the remote server, so that is not my question.

Since most of the install scripts we use need root permissions, and because you do not use NOPASSWD for root for obvious reasons, is this possible, and how?

link|improve this question
feedback

2 Answers

Can't you prepend "sudo" and the password to the stuff that gets piped into ssh? I've done this before when remote driving interfaces with expect.

link|improve this answer
feedback

Create a dedicated user account on the server just to use for this purpose. Configure /etc/sudoers on the server so that the only commands the dedicated user account can run are the ones you desire. Also configure /etc/sudoers on the server so the dedicated user account doesn't require a password to use sudo. Then ssh to the server as the dedicated user and run sudo to execute the desired commands as root.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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