popen2 + passwd

Jp Calderone exarkun at flashmail.com
Tue May 16 00:04:24 EDT 2000

"Halvorson, Peter" wrote:
> 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)

 Hmmm, except I have root login disabled for any foreign

 I ended up use using the usermod util w/ a shell encryption
program.  Probably what I should have done in the first place,
it's much nicer than fiddling with pipes to other programs, imho.

Thanks for all the responses though.  At least I see why my way
didn't work now.


In the days when Sussman was a novice Minsky once came to him as he sat
hacking at the PDP-6. "What are you doing?" asked Minsky. "I am training a
randomly wired neural net to play Tic-Tac-Toe." "Why is the net wired
randomly?" asked Minsky. "I do not want it to have any preconceptions of how
to play." Minsky shut his eyes. "Why do you close your eyes?" Sussman asked
his teacher. "So the room will be empty." At that moment, Sussman was
 12:02am up 13 days, 4:30, 3 users, load average: 0.01, 0.04, 0.06

More information about the Python-list mailing list