Class: CCSH::SSH::RemoteCommand
- Inherits:
-
Object
- Object
- CCSH::SSH::RemoteCommand
- Defined in:
- lib/ccsh/ssh.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#options ⇒ Object
Returns the value of attribute options.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#private_key ⇒ Object
Returns the value of attribute private_key.
-
#return_code ⇒ Object
Returns the value of attribute return_code.
-
#return_signal ⇒ Object
Returns the value of attribute return_signal.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize ⇒ RemoteCommand
constructor
A new instance of RemoteCommand.
Constructor Details
#initialize ⇒ RemoteCommand
Returns a new instance of RemoteCommand.
30 31 32 33 34 35 36 |
# File 'lib/ccsh/ssh.rb', line 30 def initialize @command = nil @hostname = nil = [] @stdout = '' @stderr = '' end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
16 17 18 |
# File 'lib/ccsh/ssh.rb', line 16 def command @command end |
#hostname ⇒ Object
Returns the value of attribute hostname.
17 18 19 |
# File 'lib/ccsh/ssh.rb', line 17 def hostname @hostname end |
#options ⇒ Object
Returns the value of attribute options.
18 19 20 |
# File 'lib/ccsh/ssh.rb', line 18 def end |
#password ⇒ Object
Returns the value of attribute password.
21 22 23 |
# File 'lib/ccsh/ssh.rb', line 21 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
20 21 22 |
# File 'lib/ccsh/ssh.rb', line 20 def port @port end |
#private_key ⇒ Object
Returns the value of attribute private_key.
22 23 24 |
# File 'lib/ccsh/ssh.rb', line 22 def private_key @private_key end |
#return_code ⇒ Object
Returns the value of attribute return_code.
27 28 29 |
# File 'lib/ccsh/ssh.rb', line 27 def return_code @return_code end |
#return_signal ⇒ Object
Returns the value of attribute return_signal.
28 29 30 |
# File 'lib/ccsh/ssh.rb', line 28 def return_signal @return_signal end |
#stderr ⇒ Object
Returns the value of attribute stderr.
26 27 28 |
# File 'lib/ccsh/ssh.rb', line 26 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
25 26 27 |
# File 'lib/ccsh/ssh.rb', line 25 def stdout @stdout end |
#user ⇒ Object
Returns the value of attribute user.
19 20 21 |
# File 'lib/ccsh/ssh.rb', line 19 def user @user end |
Instance Method Details
#execute! ⇒ Object
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 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ccsh/ssh.rb', line 38 def execute! = { :password => @password, :keys => [@private_key], :port => @port, :host_key => ['host_key'], :timeout => ['timeout'], }.select {|key,value| value != nil} raise "something" unless CCSH::Utils.valid_ssh() Net::SSH.start(@hostname, @user, ) do |ssh| ssh.open_channel do |ch| ch.exec @command do |ch, success| raise "Could execute command #{command} on #{host}" unless success end ch.on_data do |c, data| @stdout << data end ch.on_extended_data do |c, type, data| @stderr << data end ch.on_request("exit-status") do |c,data| @return_code = data.read_long end ch.on_request("exit-signal") do |c, data| @return_signal = data.read_long end end.wait end return self end |