telnetlib
Eddie Corns
eddie at holyrood.ed.ac.uk
Fri Jan 10 12:15:36 EST 2003
"Dickerson, Dee" <Dickerson4 at dow.com> writes:
>Below is telnet code that I am trying to get going. I am going from a Windows2000 machine to a Redhat Linux machine; the ls command will not run as I can tell; it does not return any output.
>
>I need to be able to execute other commands such as ps with options such as
>
>ps -eda -format pid,command |grep legion-server,,,,, etc|
>
>I would appreciate any help that anyone could offer.
>
>
>import telnetlib
>import sys
>from hostlistdee import hostlistdee
>
>user='legion'
>pw='*******'
>
>for host in hostlistdee:
> try:
> tn=telnetlib.Telnet(host)
> tn.read_until("login: ")
> tn.write(user+'\n')
> tn.read_until('Password: ')
> tn.write(pw+'\n')
> tn.write('ls\n')
> tn.write('exit\n')
> tn.read_all()
> tn.close()
> print 'started ',host
> except:
> print 'failed ',host
> # end try
># end def
2 things. How do you know there's no output if you don't print the results
from tn.read_*? and secondly you should never close a telnet connection until
you've safely read all outstanding data because closing the connection flushes
all outstanding data and you don't see it. The 'exit' command, I think, will
cause the far end to close the connection.
More information about the Python-list
mailing list