Class: Net::SSH::Connection::Session
- Inherits:
-
Object
- Object
- Net::SSH::Connection::Session
- Defined in:
- lib/stackadmin/net-ssh.rb
Overview
Defined Under Namespace
Classes: CommandExecutionFailed, CommandFailed
Instance Method Summary collapse
-
#exec_sc!(command) ⇒ Hash
A convenience method for executing a command and interacting with it.
Instance Method Details
#exec_sc!(command) ⇒ Hash
A convenience method for executing a command and interacting with it.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/stackadmin/net-ssh.rb', line 31 def exec_sc!(command) stdout_data, stderr_data = '', '' exit_code, exit_signal = nil, nil self.open_channel do |channel| channel.exec(command) do |_, success| raise CommandExecutionFailed, "Command \"#{command}\" was unable to execute" unless success channel.on_data do |_, data| stdout_data += data end channel.on_extended_data do |_, _, data| stderr_data += data end channel.on_request('exit-status') do |_, data| exit_code = data.read_long end channel.on_request('exit-signal') do |_, data| exit_signal = data.read_long end end end self.loop raise CommandFailed, "Command \"#{command}\" returned exit code #{exit_code}" unless exit_code == 0 { stdout: stdout_data, stderr: stderr_data, exit_code: exit_code, exit_signal: exit_signal } end |