Method: EventMachine::Ssh::Shell#expect

Defined in:
lib/em-ssh/shell.rb

#expect(strregex, send_str = nil, opts = {}, &blk) ⇒ Shell, String

Wait for a number of seconds until a specified string or regexp is matched by the data returned from the ssh connection. Optionally send a given string first.

If a block is not provided the current Fiber will yield until strregex matches or :timeout # is reached.

If a block is provided expect will return immediately.

Examples:

expect a prompt

expect(' ~]$ ')

send a command and wait for a prompt

expect(' ~]$ ', '/sbin/ifconfig')

expect a prompt and within 5 seconds

expect(' ~]$ ', :timeout => 5)

send a command and wait up to 10 seconds for a prompt

expect(' ~]$ ', '/etc/sysconfig/openvpn restart', :timeout => 10)

Parameters:

  • strregex (String, Regexp)

    to match against

  • send_str (String) (defaults to: nil)

    the data to send before waiting

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :timeout (Fixnum) — default: @timeout

    number of seconds to wait when there is no activity

Returns:

  • (Shell, String)

    all data received up to an including strregex if a block is not provided. the Shell if a block is provided



310
311
312
313
314
315
316
# File 'lib/em-ssh/shell.rb', line 310

def expect(strregex, send_str = nil, opts = {}, &blk)
  assert_channel!
  shell.expect(strregex,
               send_str,
               {:timeout => @timeout, :log => self }.merge(opts),
              &blk)
end