popen2 + passwd

Halvorson, Peter Peter_Halvorson at nfuel.com
Mon May 15 20:46:52 EDT 2000

Is it just me or does o.write look odd?  It seems to be writing to the 
output end of the pipe.

In any case, if it is a tty problem, the simplest expect-like solution 
may be to use the telnetlib.py to fire off a telnet session.  Something 
like the following (you may have to fix the prompts provided to match
your system, you may get a false hit on the shell prompt since it's
a little short).


import sys
from telnetlib import Telnet

host        = 'yourhost'
login       = 'root'
password    = 'xxxxxxx'
shellprompt = '# '

dialog = [
  ('login: ',                     login),
  ('Password: ',                  password),
  (shellprompt,                   'passwd bin'),
  ('New password: ',              '12345ASD'),
  ('Repeat new password: ',       '12345ASD'),
  (shellprompt,                   'exit') ]
telnet = Telnet(host)
for prompt, response in dialog:
  telnet.write(response + '\n')

More information about the Python-list mailing list