class Seeker::SSH
Constants
- PROMPT
- SLEEP
- TIMEOUT
Attributes
prompt_seen[R]
Public Class Methods
new(host, user, password, prompt=PROMPT)
click to toggle source
# File lib/seeker/ssh.rb, line 27 def initialize host, user, password, prompt=PROMPT @output = '' @prompt = prompt @prompt_seen = nil @session = nil @ssh = Net::SSH.start host, user, :password=>password, :timeout=>TIMEOUT shell_open expect @prompt end
Public Instance Methods
close(command='exit')
click to toggle source
# File lib/seeker/ssh.rb, line 21 def close command='exit' @session.send_data command +"\n" end
cmd(command)
click to toggle source
# File lib/seeker/ssh.rb, line 12 def cmd command Log.debug "SSH: #{command}" @output = '' @session.send_data command + "\n" @session.process expect @prompt @output end
Private Instance Methods
expect(regexp)
click to toggle source
# File lib/seeker/ssh.rb, line 52 def expect regexp Timeout::timeout(TIMEOUT) do @ssh.loop(SLEEP) do sleep SLEEP re = @output.match regexp @prompt_seen = re[0] if re not re end end end
shell_open()
click to toggle source
# File lib/seeker/ssh.rb, line 37 def shell_open @session = @ssh.open_channel do |channel| channel.on_data do |channel, data| $stderr.print data if Seeker.debug > 1 @output << data end channel.request_pty do |channel, success| raise NoSshShell, "Can't get PTY" unless success channel.send_channel_request 'shell' do |channel, success| raise NoSshShell, "Can't get shell" unless success end end end end