Class: Vx::Lib::Shell::SSH
- Inherits:
-
Object
- Object
- Vx::Lib::Shell::SSH
- Defined in:
- lib/vx/lib/shell/ssh.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #exec(*args, &block) ⇒ Object
-
#initialize(ssh) ⇒ SSH
constructor
A new instance of SSH.
Constructor Details
#initialize(ssh) ⇒ SSH
Returns a new instance of SSH.
12 13 14 |
# File 'lib/vx/lib/shell/ssh.rb', line 12 def initialize(ssh) @connection = ssh end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/vx/lib/shell/ssh.rb', line 10 def connection @connection end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/vx/lib/shell/ssh.rb', line 10 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/vx/lib/shell/ssh.rb', line 10 def @options end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/vx/lib/shell/ssh.rb', line 10 def user @user end |
Instance Method Details
#exec(*args, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vx/lib/shell/ssh.rb', line 16 def exec(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} command = args.first home = [:home] || "$HOME" exit_code = nil timeout = Shell::Timeout.new .delete(:timeout) read_timeout = Shell::ReadTimeout.new .delete(:read_timeout) prefix = "/usr/bin/env - TERM=ansi USER=$USER HOME=#{home} SHELL=/bin/bash /bin/bash -l" if command command = "#{prefix} -c #{Shellwords.escape command}" else command = prefix end channel = spawn_channel command, read_timeout, , &block channel.on_request("exit-status") do |_,data| exit_code = data.read_long end channel.on_request("exit-signal") do |_,data| exit_code = data.read_long * -1 end pool channel, timeout, read_timeout compute_exit_code command, exit_code, timeout, read_timeout end |