0

I run python script using telnetlib on linux virtual machine.

99% of the time, tn.write('\n') works smoothly.

But there's a case when a server is just booted up, in the real console, first user logged in needs to press Enter on the keyboard after seeing the login information to proceed. If they don't press Enter, they will stay with the login information forever.

And this time tn.write('\n') doesn't work simply same as manually press Enter in the console. Even not the ways to press Enter using script below:

tn.write('\r\n')
tn.write("\r\n".encode('ascii'))

# or with time.sleep(1) inserted with any value

My script can connect to the server with password, just like every time.

By using read_some or read_eager, I'm pretty sure that there's(my script encounters) only a table of information on the console, no prompt, no indication to ask user press Enter, just if you press Enter you go into the console and get your first prompt.

(If I manually log in, press Enter and exit, my script runs smoothly as it's not the first user anymore.)

user3352539
  • 79
  • 1
  • 1
  • 8
  • By jumping out from the perspective of telnet, I use os.system or subprocess.call to type enter.. It seemingly works, is there other ways? – user3352539 Mar 13 '14 at 00:27
  • It doesn't work every time, please, anyone could figure that out? – user3352539 Mar 17 '14 at 17:57
  • do you have the same problem ("can't login via telnet after reboot") with ssh? Try [`fabric`](http://fabfile.org) to run commands remotely – jfs Mar 26 '14 at 19:44

1 Answers1

0

Try calling for debug, I generally use this in the begin:

tn = telnetlib.Telnet(ip_to_connect)

tn.set_debuglevel(5)

This helps me get what the console is returning, when its an ASCII console, you will get something like: '\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\r\n' and it's possible to use this information in read.until()

Joey Phillips
  • 1,543
  • 2
  • 14
  • 22