I am trying to parse the bootup sequence of a device. I connect using telnet to the terminal server, which connects me to the serial port of the device.
The following script works and logs me in, which means the terminal is responsive to the script & sendline:
import pexpect
child = pexpect.spawn ('telnet x.x.x.x yyyy')
child.expect ('login: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('[email protected]')
The following fails:
import pexpect
child = pexpect.spawn ('telnet x.x.x.x yyyy')
child.expect ('Hit [Enter] to boot immediately, or space bar for command prompt.', timeout=300)
child.send ('\x20')
print child.before
My aim is when the device boots, it just does line-oriented output with my expected string coming somewhere in the middle of scroll.
The above script is unable to match. Upon further debugging "child.before" shows me last line prior to login prompt. What is the cause of the failure?
Bingo! The escape character was what I was missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With