Class: Net::SSH::Connection::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/additions/NetSshConnectionSession.rb

Overview

Reopen Net::SSH to allow for a “realtime” ssh run that prints out stdout immediately upon receipt, so you can interactively watch the results.

Instance Method Summary collapse

Instance Method Details

#exec_realtime(cmd) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/additions/NetSshConnectionSession.rb', line 4

def exec_realtime(cmd)
  open_channel do |channel|
    channel.exec(cmd) do |ch, success|
      abort "could not execute command: #{cmd}" unless success

      channel.on_data do |ch, data|
        puts "#{data}"
      end

      channel.on_extended_data do |ch, type, data|
        warn "ERROR: #{data}"
      end
    end
  end
  loop
end