Professional Web Applications Themes

expect.rb - Ruby

Does anybody know where I can get the expect.rb ? As defined, here in Japanese: http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=expect.rb See the ab-lib translation below: ################################################## ###### #ab-lib Translated Japanese ################################################## ###### The Expect Library is tlc's Expect package. In Ruby it is part of the IO class. Example usage: IO#expect(pattern, timeout=99999) With the expect method you can directly interact with inline text interfaces. Expect uses string patterns and Regexp to read the input from device. One example, of a piece of equipment where Expect could be used might be a router with either ssh or telnet enabled. Expect can be called in a ...

  1. #1

    Default expect.rb

    Does anybody know where I can get the expect.rb ?

    As defined, here in Japanese:
    http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=expect.rb

    See the ab-lib translation below:

    ################################################## ######
    #ab-lib Translated Japanese
    ################################################## ######

    The Expect Library is tlc's Expect package. In Ruby it is part of the IO class.

    Example usage:
    IO#expect(pattern, timeout=99999)

    With the expect method you can directly interact with inline text
    interfaces. Expect uses string patterns and Regexp to read the input
    from device.

    One example, of a piece of equipment where Expect could be
    used might be a router with either ssh or telnet enabled. Expect can be
    called in a Ruby program to process the inline text on the host device.

    When an expected pattern is found, a response will be sent. If the
    pattern does not appear, the timeout will expire and move to the next
    statement. Practically, Expect has been used to reset passwords on routers.
    Expect has been used to run nightly updates on telephone switches.
    Expect has been used to setup HP printers. Additionally, expect can be
    used to modify any device with a inline text interface.

    --
    ------------------------------------------
    Ted Knab
    Chester, MD 21619
    ------------------------------------------
    35570707f6274702478656021626f6c6964796f6e602f66602 478656
    02e6164796f6e60237471647560216e6460276c6f62616c602 57e696
    4797e2a0


    Theodore Guest

  2. #2

    Default Re: expect.rb

    I found some example expect code for Ruby now I just need to find the
    library:

    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/30822

    http://rubystuff.org/treasures/RubyTreasures-0.4/test/test_expect.rb

    http://www.ksky.ne.jp/~sakae/d2/20518.html

    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/35746

    On 11/02/04 13:37 +0900, Theodore Knab wrote: 

    --
    ------------------------------------------
    Ted Knab
    Chester, MD 21619
    ------------------------------------------
    35570707f6274702478656021626f6c6964796f6e602f66602 478656
    02e6164796f6e60237471647560216e6460276c6f62616c602 57e696
    4797e2a0


    Theodore Guest

  3. #3

    Default Re: expect.rb -- self solved

    If there is a better module let me know.

    Never mind I found a working expect module which I added to '/usr/lib/ruby/1.8/expect.rb':

    $expect_verbose = false

    class IO
    def expect(pat,timeout=9999999)
    buf = ''
    case pat
    when String
    e_pat = Regexp.new(Regexp.quote(pat))
    when Regexp
    e_pat = pat
    end
    while true
    if IO.select([self],nil,nil,timeout).nil? then
    result = nil
    break
    end
    c = getc.chr
    buf << c
    if $expect_verbose
    STDOUT.print c
    STDOUT.flush
    end
    if mat=e_pat.match(buf) then
    result = [buf,*mat.to_a[1..-1]]
    break
    end
    end
    if block_given? then
    yield result
    else
    return result
    end
    nil
    end
    end

    Additionally, this expect test worked pretty good for me:
    http://www.ksky.ne.jp/~sakae/d2/20518.html

    --- sample expect ---------------------------------
    require 'pty'
    require 'expect'

    x = ''
    PTY.spawn("telnet foo.bar.com") do # Do connect
    |r_f,w_f,pid|
    w_f.sync = true
    $expect_verbose = false ### if true, Can monitor session

    status = r_f.expect('login: ',timeout=30) ### login
    if status.nil?
    puts "No responce foo.bar.com"
    exit
    end
    w_f.print "hoge\n"
    r_f.expect('word: ') do
    w_f.print "hoge-password\n"
    end

    r_f.expect('foo% ') do ### DO ls
    w_f.print "ls -l\n"
    end
    r_f.expect('foo% ') do |output|
    x = output[0]
    end

    begin ### logout
    w_f.print "logout\n"
    rescue
    end
    end

    print "\n=====\nhost foo hoge's home-dir files are \n"
    print x
    print "\n"
    -------------------------------------------------------------------



    --
    ------------------------------------------
    Ted Knab
    Chester, MD 21619
    ------------------------------------------
    35570707f6274702478656021626f6c6964796f6e602f66602 478656
    02e6164796f6e60237471647560216e6460276c6f62616c602 57e696
    4797e2a0


    Theodore Guest

  4. #4

    Default Re: expect.rb

    On Wed, 11 Feb 2004, Theodore Knab wrote:
     
    <snip>

    what kind of process are you trying to 'expect' ?

    -a
    --

    ATTN: please update your address books with address below!

    ================================================== =============================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
    | STP :: http://www.ngdc.noaa.gov/stp/
    | NGDC :: http://www.ngdc.noaa.gov/
    | NESDIS :: http://www.nesdis.noaa.gov/
    | NOAA :: http://www.noaa.gov/
    | US DOC :: http://www.commerce.gov/
    |
    | The difference between art and science is that science is what we
    | understand well enough to explain to a computer.
    | Art is everything else.
    | -- Donald Knuth, "Discover"
    |
    | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
    ================================================== =============================

    Ara.T.Howard Guest

Similar Threads

  1. Replies: 4
    Last Post: September 19th, 10:27 AM
  2. About Expect.
    By Dr. in forum PERL Miscellaneous
    Replies: 4
    Last Post: October 27th, 05:51 PM
  3. Net::SCP::Expect
    By Jose Malacara in forum PERL Beginners
    Replies: 3
    Last Post: October 1st, 04:15 PM
  4. INC is not what I expect
    By niz in forum PERL Miscellaneous
    Replies: 2
    Last Post: July 23rd, 08:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139