I am trying to automate a set of telnet commands used when configuring a linux server. I am currently trying to use Python 2.7 for this and thought that telnetlib would be the way to go. But unfortunatly it doesn't work as I would expect.
tn = telnetlib.Telnet(ip, port)
print tn.read_until("SysCLI>")
tn.write("help" +"\n")
print tn.read_until("Registered components are:", 10)
This will terminate after 10 seconds printing nothing but the first print line: "SysCLI>". I have tried different combinations of "carriage return" and "line feed" including "\r", "\r\n", "\n\r", none of them seem to help. Do anyone have a suggestion on what I am missing?
Update: I tried my code on a different server and it seems to work fine:
ip = "www.google.com"
port = 80
tn = telnetlib.Telnet(ip, port)
tn.write("Get / HTTP/1.1" +"\n" +"\n")
print tn.read_some()
So I am thinking that my problem is the server that needs some special character for sending messages.