popen2 + passwd

Halvorson, Peter Peter_Halvorson at nfuel.com
Tue May 16 02:46:52 CEST 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).


peter


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:
  sys.stdout.write(telnet.read_until(prompt))
  telnet.write(response + '\n')
telnet.close()
sys.exit(0)





More information about the Python-list mailing list