Class: SSHFuncs
- Inherits:
-
Object
- Object
- SSHFuncs
- Defined in:
- lib/ssh_funcs.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#remote_cmd ⇒ Object
Returns the value of attribute remote_cmd.
Instance Method Summary collapse
-
#initialize(hostname) ⇒ SSHFuncs
constructor
A new instance of SSHFuncs.
- #run_cmd(cmd) ⇒ Object
- #ssh_channel ⇒ Object
Constructor Details
#initialize(hostname) ⇒ SSHFuncs
Returns a new instance of SSHFuncs.
8 9 10 11 12 13 14 |
# File 'lib/ssh_funcs.rb', line 8 def initialize(hostname) @hostname = hostname @output @run_cmd @ssh ssh_channel end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/ssh_funcs.rb', line 6 def hostname @hostname end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/ssh_funcs.rb', line 5 def output @output end |
#remote_cmd ⇒ Object
Returns the value of attribute remote_cmd.
6 7 8 |
# File 'lib/ssh_funcs.rb', line 6 def remote_cmd @remote_cmd end |
Instance Method Details
#run_cmd(cmd) ⇒ Object
24 25 26 27 28 |
# File 'lib/ssh_funcs.rb', line 24 def run_cmd(cmd) # capture all stderr and stdout output from a remote process @output = @ssh.exec!(cmd) puts "SSH CMD OUTPUT: #{@output}" if DEBUG end |
#ssh_channel ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/ssh_funcs.rb', line 16 def ssh_channel begin @ssh = Net::SSH.start(@hostname, 'root') rescue Exception => e puts "Couldn't establish SSH session with #{@hostname}, received exception: #{e}" end end |