我有以下脚本:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
Net::SSH.start('host1', 'root', :password => "mypassword1") do |ssh|
stdout = ""
ssh.exec("cd /var/example/engines/")
ssh.exec!( "pwd" ) do |channel, stream, data|
stdout << data if stream == :stdout
end
puts stdout
ssh.loop
end
Run Code Online (Sandbox Code Playgroud)
我得到了/root,而不是 /var/example/engines/
看看是否有类似于 file(utils?) cd 块语法的内容,否则只需在同一个子 shell 中运行命令,例如 ssh.exec "cd /var/example/engines/; pwd" ?
| 归档时间: |
|
| 查看次数: |
8567 次 |
| 最近记录: |