lib/em-ssh/connection/channel/interactive.rb
# Wait for a number of seconds until a specified string or regexp is matched by the
# data returned from the ssh channel. 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.
#
# @param [String, Regexp] strregex to match against
# @param [String] send_str the data to send before waiting
# @param [Hash] opts
# @option opts [Fixnum] :timeout (@timeout) number of seconds to wait when there is no activity
# @return [Shell, String] all data received up to an including strregex if a block is not provided.
#                         the Shell if a block is provided
# @example expect a prompt
#   expect(' ~]$ ')
# @example send a command and wait for a prompt
#   expect(' ~]$ ', '/sbin/ifconfig')
# @example expect a prompt and within 5 seconds
#   expect(' ~]$ ', :timeout => 5)
# @example send a command and wait up to 10 seconds for a prompt
#   expect(' ~]$ ', '/etc/sysconfig/openvpn restart', :timeout => 10)
Wait for a number of seconds until a specified string or regexp is matched by the
data returned from the ssh channel. 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.
Wait for a number of seconds until a specified string or regexp is matched by the data returned from the ssh channel . 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 .
def expect(strregex, send_str = nil, opts = {})
            send_str, opts = nil, send_str if send_str.is_a?(Hash)
            if block_given?
              Fiber.new {
                yield send_str ? send_and_wait(send_str, strregex, opts) : wait_for(strregex, opts)
              }.resume
              self
            else
              send_str ? send_and_wait(send_str, strregex, opts) : wait_for(strregex, opts)
            end
          end
def expect ( strregex , send_str = nil , opts = { } ) send_str , opts = nil , send_str if send_str . is_a? ( Hash ) if block_given? Fiber . new { yield send_str ? send_and_wait ( send_str , strregex , opts ) : wait_for ( strregex , opts ) } . resume self else send_str ? send_and_wait ( send_str , strregex , opts ) : wait_for ( strregex , opts ) end end
Wait for a number of seconds until a specified string or regexp is matched by the
data returned from the ssh channel.
Wait for a number of seconds until a specified string or regexp is matched by the data returned from the ssh channel .
all data received up to an including strregex if a block is not provided. the Shell if a block is provided
all data received up to an including strregex if a block is not provided . the Shell if a block is provided
Shell, String
strregex
<not_specific>
send_str
<not_specific>
opts
:timeout (@timeout) number of seconds to wait when there is no activity
: timeout ( @timeout ) number of seconds to wait when there is no activity
<not_specific>
None
example
expect a prompt expect(' ~]$ ')
expect a prompt expect ( ' ~ ] $ ' )
example
send a command and wait for a prompt expect(' ~]$ ', '/sbin/ifconfig')
send a command and wait for a prompt expect ( ' ~ ] $ ' ' / sbin / ifconfig ' )
example
expect a prompt and within 5 seconds expect(' ~]$ ', :timeout => 5)
expect a prompt and within 5 seconds expect ( ' ~ ] $ ' : timeout = > 5 )
example
send a command and wait up to 10 seconds for a prompt expect(' ~]$ ', '/etc/sysconfig/openvpn restart', :timeout => 10)
send a command and wait up to 10 seconds for a prompt expect ( ' ~ ] $ ' ' / etc / sysconfig / openvpn restart ' : timeout = > 10 )