[Tutor] pexpect

Steve Poe steve.poe at gmail.com
Sat Sep 20 17:59:09 CEST 2008


James,

I've not used pexpect, but I've done  this on a Cisco switch. I found  
using
time.sleep and read_until of the telnet class to be helpful.

10      tn = telnetlib.Telnet('<IP>')
  11     #tn.set_debuglevel(9)
  12     tn.read_until('Username: \xff', 5)
  13     time.sleep(10)
  14     tn.write('<name>\n')
  15     tn.read_until('\r\nPassword: ', 5)
  16     #time.sleep(2)
  17     tn.write('<password>\n')
  18     tn.read_until('#', 5)
  19     tn.write('term len 0 \n')
  20     tn.read_until('#', 5)
  21     tn.write('show version |  i restarted\n')
  22     RouterStartupTimestamp = tn.read_until('#', 2)
  23     tn.read_until('#', 2)
  24     tn.write('show call history voice last 100\n')


HTH,

Steve

On Sep 20, 2008, at 8:43 AM, James wrote:

> Folks,
>
> Does anyone here have experience with pexpect? I'm trying to write a
> pexpect script which will log into a network device, gather
> statistics, and then dump the raw output into a file (or a string so
> that I can manipulate it).
>
> I'm not having much luck. Because the connection is telnet I was able
> to use wireshark (a sniffer) to see the traffic between my computer
> (which is running the pexpect script) and the network device.
> Everything seems to go find until I "expect" the network device's
> prompt and it just hangs. Eventually pexpect throws an exception and
> times out.
>
> I'd be happy to share some code when I get to the computer I've been
> testing on. :) In the time being, has anyone seen a problem like this
> before?
>
> Thanks!
> -j
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list