My environment is configured with SSH password-less authentication for the user "master" between a node Server (Rundeck server) and node Target (remote Solaris host).
On Target, I want to execute a script /app/acme/stopApp.sh
with the user appmanager
.
Normally, when I need to run the script manually, I use:
ssh master@server sudo su - appmanager
or simply:
ssh -t master@server 'sudo su - appmanager'
which works without the password and finally run (as appmanager):
/app/acme/stopApp.sh
But I'm unable to figure out how to reproduce these steps using Net::SSH.
When I execute sudo su - appmanager
and then /app/acme/stopApp.sh
,
I'm doing it in a sub-shell, right?
require 'rubygems'
require 'net/ssh'
require 'net/scp'
require 'crypt/blowfish'
require 'yaml'
#
# ...
#
Net::SSH.start( host, user, :password => password ) do |session|
# It's possible to proceed in this way?
cmd = 'sudo su - appmanager;/app/acme/stopApp.sh'
ses = session.exec!( cmd )
end
I realized that if I try to execute something like I'm on the Target server:
sudo su -c /app/acme/stopApp.sh appmanager
I receive the message below:
We trust you have received the usual lecture from the local System Administrator.
It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility. Password:
Password: