sudo:ruby:ssh 后未找到命令

sudo:ruby:ssh 后未找到命令

我正在使用 ec2 实例,并尝试在 ssh 连接到另一个实例后在该实例上执行 ruby​​ 脚本。我有一个更新配置文件的 ruby​​ 脚本,因此我需要以超级用户身份运行该脚本。当我在该实例上手动运行脚本时,sudo ruby recreate-532d01c.rb出现的错误是

sudo: ruby: command not found

无需 root 权限即可运行简单脚本,例如ruby file_1.rb

使用 rvmsudo 代替 sudo 执行脚本时会发出警告,

ubuntu@ip-10-0-0-111:~$ rvmsudo ruby recreate-82bb000012.rb 
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:

    export rvmsudo_secure_path=1

to avoid the warning, put it in shell initialization file to make it persistent.

In case there is no `secure_path` in `/etc/sudoers`. Run:

    export rvmsudo_secure_path=0

to avoid the warning, put it in shell initialization file to make it persistent.

我尝试从要测试的其中一个实例的 rails 控制台执行以下命令,但它无法将 ruby​​ 识别为命令

1.9.3-p545 :002 > system("ssh -i /home/ubuntu/.ssh/own_key.pem ubuntu@**.***.***.** ruby execute-52d.rb")
bash: ruby: command not found

我尝试了网络上可能的解决方案,但无法解决问题。我的一个旧 aws 帐户运行着相同的配置,这是一个新创建的帐户。不确定这是否是问题,因为目前 ec2 实例默认属于 vpc,并且在 2013 年 12 月之后发生了一些变化

答案1

您收到的错误表明ruby不在 sudo 中$PATH。要解决这个问题,您需要正确导出您的环境:

sudo -E ruby

或者,直接使用完整路径。type ruby以普通用户身份运行,然后使用sudo。例如:

$ type ruby
ruby is /usr/bin/ruby
$ sudo /usr/bin/ruby

相关内容