我的环境配置为在节点Server(Rundeck服务器)和节点Target(节点)之间为用户 “master”远程Solaris主机)。使用Net :: SSH Ruby库来执行需要sudo su的远程命令 - 另一个用户
在目标上,我想执行脚本/app/acme/stopApp.sh
与用户appmanager
。
通常,当我需要手动运行该脚本,我使用:
ssh [email protected] sudo su - appmanager
或者干脆:
ssh -t [email protected] 'sudo su - appmanager'
其作品,未经密码,最后运行(如AppManager的):
/app/acme/stopApp.sh
但我无法弄清楚如何使用Net :: SSH重现这些步骤。 当我执行sudo su - appmanager
,然后/app/acme/stopApp.sh
, 我在做一个子shell,对吧?
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
我意识到,如果我试图像我在目标服务器上执行的东西:
sudo su -c /app/acme/stopApp.sh appmanager
我收到以下消息:
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:
感谢Tin Man对文字的改进。我不是以英语为母语的人,所以你的行为可以帮助我更多地了解这门语言。 – Bera