Class: SSHFuncs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostnameObject

Returns the value of attribute hostname.



6
7
8
# File 'lib/ssh_funcs.rb', line 6

def hostname
  @hostname
end

#outputObject (readonly)

Returns the value of attribute output.



5
6
7
# File 'lib/ssh_funcs.rb', line 5

def output
  @output
end

#remote_cmdObject

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_channelObject



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