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

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

Instance Method Summary collapse

Instance Method Details

#garbage?(data) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ssh.rb', line 23

def garbage?(data)
  data.start_with?('bash: cannot set terminal process group') || data.start_with?('bash: no job control in this shell')
end

#stream!(command) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ssh.rb', line 2

def stream!(command)
  exit_code = 0
  channel = self.open_channel do |channel|
    channel.exec command do |ch, success|
      raise 'could not execute command' unless success
      ch.on_data do |c, data|
        yield :stdout, data unless garbage? data
      end
      ch.on_extended_data do |c, type, data|
        yield :stderr, data unless garbage? data
      end
      ch.on_request('exit-status') do |c, data|
        exit_code = data.read_long
      end
    end
  end
  channel.wait
  raise "command failed #{command}!" if exit_code != 0
  nil
end