I'm very new to python scripting, but I thought I would give it a go to see if I can automate a few simple tasks I preform regularly over Telnet.
I found a basic python telnet script:
import getpass
import sys
import telnetlib
HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()
This 'seems' to work, but returns nothing to the console. Since the login process takes a few seconds, I figure it's just going too fast & needs to wait for the user prompt. So I tried adding this.
tn.read_until(">")
It does not work... I get this error
File "test.py", line 16, in <module>
tn.read_until(">")
File "/usr/lib/python2.7/telnetlib.py", line 319, in read_until
return self.read_very_lazy()
File "/usr/lib/python2.7/telnetlib.py", line 395, in read_very_lazy
raise EOFError, 'telnet connection closed'
EOFError: telnet connection closed
I feel like I'm missing something simple... but the solution seems to be alluding me. Any input will be highly appreciated!