telnetlib

Bengt Richter bokr at oz.net
Fri Jan 10 14:35:51 EST 2003


On Fri, 10 Jan 2003 09:11:55 -0600, "Dickerson, Dee" <Dickerson4 at dow.com> wrote:

>This message is in MIME format. Since your mail reader does not understand
>this format, some or all of this message may not be legible.
FYI, by posting HTML on usenet, you create in some people an emotional obstacle
to reading further, even if there is a cleartext part at the beginning.

>
>------_=_NextPart_001_01C2B8BA.9C916F80
>Content-Type: text/plain;
>	charset="iso-8859-1"
>
>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
>
>------_=_NextPart_001_01C2B8BA.9C916F80
>Content-Type: text/html;
[... 272 lines (9599 bytes) of machine generated garbage snipped ...]

First, can you telnet manually to the first host using exactly the sequence
of data transfer above?

Second, if tn.read_all() returns some data, what are you doing with it?
What happens if you put "print tn.read_all()" ?

I don't know if you might have to do some reading of responses before
sending additional commands, but it might not be safe to assume there
are no buffering limits anywhere in your session activity. Of course,
for that you wouldn't want to use a read that would hang until the other
side closes the connection.

Regards,
Bengt Richter




More information about the Python-list mailing list