How to open and search a file in a telnet session with Python
Question: I'm using the following code to log into a server and go to a particular
directory (where the logfile I want to search for a string resides). I have
accomplished this with the Paramiko module (ssh), fairly straightforward. But
the telnetlib module does not have many functions that I see to accomplish
this. Does anyone know how I would open the file and search through it for a
particular string (The server in question only allows Telnet logins - no ssh)
... Thanks:

    
    
    import sys
    import telnetlib
    
    
    
    
    
    HOST = "10.28.46.14"
    user = raw_input("Enter your username: ")
    password = ""
    
    tn = telnetlib.Telnet(HOST)
    
    tn.read_until("login: ")
    tn.write(user + "\n")
    
    if password == "":
        tn.read_until("Password: ")
        tn.write(password + "\n")
        #print "Login successful!"
    else:
        print "Your password is incorrect."
    
    
    tn.write("cd /var/opt/mylog/log\n")
    tn.write("ls\n")
    tn.read_until("\n")
    #tn.write("exit\n")
    
    my_ls = tn.read_until("my.log")
    
    
    print my_ls
    


Answer: Did you check with the owner of the machine about ssh vs telnet? There aren't
many operating systems that ship with telnet out of the box anymore, because
telnet is subject to replay attacks.

What if you tell tn to do a grep? You might append an "echo $?" after the
grep, to get an exit code - 0 means there was one or more matches, anything
else means there weren't any.

