1

I made a script in python that uses the telnetlib module for telnetting into a linux device, running an install.sh file, then rebooting upon completion. Upon completeion of the install.sh script, I added a line that sends echo "install complete" to the terminal. Unfortunately, read_until("install complete") and expect(["install complete"]) don't detect this echo.

tn = telnetlib.Telnet(ip)
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("cd [file path to the install script]")#echoes "install complete" when finished
tn.write("./install.sh\n")
tn.read_until("install complete")  #where the process hangs returns None if I add timeout parameter

Does telnetlib not reach echo statements or should I use another module or language? If I run the installer manually, I can confirm "install complete" echos as expected.

pwillig
  • 101
  • 1
  • 7
  • Are you sure the "install complete" actually makes it over the wire? Without knowledge how telnet handles the situation: The string may end up in a local buffer, waiting for a newline-character or flush to stdout – user2722968 Aug 30 '13 at 06:18
  • I set the debug_level to 10, and see where the install command is sent, and see its output being received in the debug output, but for whatever reason, "install complete" never appears in the stream. Is there a way to flush whatever has been stored in the buffer? read_until() appears to read commands that were executed before it was called. – pwillig Aug 30 '13 at 13:33
  • Are you sure it's "install complete\n" and there is a newline after echo ... in install.sh so the command actually gets executed? – user2722968 Aug 30 '13 at 16:39

1 Answers1

1

The code as shown doesn't include a newline ("\n") after the cd command, so the actual data sent appears likely to be "cd somepath./install.sh\n" which isn't going to work...

Also I'd avoid using the term "echo" here, since with telnet "echo" is really the part where the characters you send are sent back to you (for remote echo). In this case, whether that happens or not, the read_until() wouldn't care. In short, this isn't about echo at all.

Peter Hansen
  • 21,046
  • 5
  • 50
  • 72