Hi All, This is my first post (long time lurker) Is anyone aware of a compatible library to python's "pexpect"? What I'm looking for is the pexpect.interact() function in a ruby library/gem. I don't see an equivilent in net/ssh, /net/telnet, ruby expect, etc... This is the excerpt from the python library " interact(self, escape_character='\x1d', input_filter=None, output_filter=None) This gives control of the child process to the interactive user (the human at the keyboard). Keystrokes are sent to the child process, and the stdout and stderr output of the child process is printed." For a general idea of what I'm using python pexpect.interact for is: script logs into device script runs a few commands (show ip interface brief, show log, show ver etc.) prints some generalizations (router is receiving errors on port blah blah, or last user logged in was (user), etc...) script then turns over control of the router prompt to me the user (this is the pexpect.interact() part) Any help would be greatly appreciated. Thanks, FamGrudenza
on 2013-03-19 01:14
on 2013-03-19 08:34
On Tue, Mar 19, 2013 at 1:14 AM, Steve Jarvis <lists@ruby-forum.com> wrote: > Hi All, > > This is my first post (long time lurker) > > Is anyone aware of a compatible library to python's "pexpect"? Does that something like Ruby's IO#expect? irb(main):001:0> IO.instance_method :expect NameError: undefined method `expect' for class `IO' from (irb):1:in `instance_method' from (irb):1 from /usr/bin/irb:12:in `<main>' irb(main):002:0> require 'expect' => true irb(main):003:0> IO.instance_method :expect => #<UnboundMethod: IO#expect> $ ri -T IO#expect IO#expect (from ruby core) ------------------------------------------------------------------------------ expect(pat,timeout=9999999) { |result| ... } ------------------------------------------------------------------------------ Reads from the IO until pattern pat matches or the timeout is over. It returns an array with the read buffer, followed by the matches. If a block is given, the result is yielded to the block and returns nil. The optional timeout parameter defines, in seconds, the total time to wait for the pattern. If the timeout expires or eof is found, nil is returned or yielded. However, the buffer in a timeout session is kept for the next expect call. The default timeout is 9999999 seconds. Kind regards robert
on 2013-03-19 16:19
Huh. I use something like this.... This is an extremely old script of mine but still does the job. require 'rubygems' > > > > > @ssh.close > > end > > > > end > > > I then wrap it for different devices like F5 LTM or Cisco IOS. creds[:prompt] = /.*>|.*#/ ssh.cmd("en\r#{creds[:enable]}") ssh.cmd("term len 0") config = @ssh.cmd("show run") But if you browse github there are even more elaborate things people have built out there for device automation/interaction. I don't know if you need pexpect but i am not that familiar with it. As a Sr Neteng I can tell you I've never used it and I'm an automation loon! On Tue, Mar 19, 2013 at 12:34 AM, Robert Klemme
on 2013-03-21 23:05
Full Disclosure! I'm one of the founders of Scriptrock..try it with our product. We are in the middle of readying for launch, but most of the features you've described we do at the moment and you can log in now ;) Cliff Rosson wrote in post #1102299: > Huh. I use something like this.... > > This is an extremely old script of mine but still does the job. > > require 'rubygems' >> >> >> >> >> @ssh.close >> >> end >> >> >> >> end >> >> >> > > I then wrap it for different devices like F5 LTM or Cisco IOS. > > creds[:prompt] = /.*>|.*#/ > ssh.cmd("en\r#{creds[:enable]}") > ssh.cmd("term len 0") > config = @ssh.cmd("show run") > > But if you browse github there are even more elaborate things people > have > built out there for device automation/interaction. I don't know if you > need > pexpect but i am not that familiar with it. As a Sr Neteng I can tell > you > I've never used it and I'm an automation loon! > > > > On Tue, Mar 19, 2013 at 12:34 AM, Robert Klemme Fu
on 2013-03-22 02:53
Reading up on this now and sending to my Neteng team. The opening video describes our problems to a T but maybe they do for many organizations. Looks exciting. I look forward to exploring more details.
on 2013-03-22 14:23
I use expect4r for some command line programs to login to cisco devices. It includes an interact. https://rubygems.org/gems/expect4r
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.