class Net::SSH::Connection::Session

Public Instance Methods

exec_sudo(command, prompt = /password/, &block) click to toggle source
# File lib/nuggets/net/ssh.rb, line 31
def exec_sudo(command, prompt = /password/, &block)
  block ||= lambda { |data| ask(data) { |q| q.echo = false } }

  open_channel { |ch|
    ch.request_pty

    ch.exec("sudo #{command}") { ch.on_data { |_, data|
      ch.send_data("#{block[data]}\n") if data =~ prompt
    } }

    ch.wait
  }
end