目前我正在使用反引号方法调用远程脚本,它可以工作,但感觉错误且令人讨厌......
`ssh user@host $(echo "~/bin/command \\\"#{parameter}\\\"")`
Run Code Online (Sandbox Code Playgroud)
有人可以给我更好的表达方式吗?
非常感谢。
如果这就是你所追求的,我会把它做得漂亮一点:
#!/usr/bin/env ruby
# encoding: utf-8
home = "/path/to/users/home/on/remote"
binary = File.join(home, "bin", "command")
command = "#{binary} '#{parameter}'"
puts `ssh user@host #{command}`
Run Code Online (Sandbox Code Playgroud)
否则,您可以使用net-ssh库,并执行如下操作:
#!/usr/bin/env ruby
# encoding: utf-8
require 'net/ssh'
Net::SSH.start('host', 'user', :password => "<your-password>") do
home = "/path/to/users/home/on/remote"
binary = File.join(home, "bin", "command")
command = "#{binary} '#{parameter}'"
output = ssh.exec!(command)
puts output
end
Run Code Online (Sandbox Code Playgroud)
显然,有一些自动方法可以捕获远程用户的主目录路径,但我跳过了这一部分。