ssh-exec

ssh-exec is a wrapper around Net::SSH based on a StackOverflow answer, allowing to easily capture standard output, standard error, and the exit code of a command executed over Net::SSH.

Examples

require 'net/ssh'
require 'ssh-exec'

Net::SSH.start('somehost', 'someuser') do |ssh|
  result = SshExec.ssh_exec!(ssh, 'echo I am remote host')
  puts result.stdout  # "I am remote host"
  puts result.stderr  # ""
  puts result.exit_status  # 0

  result = SshExec.ssh_exec!(ssh, 'false')
  puts result.exit_status  # 1
end

License

Apache License, Version 2.0