root password in a .py script

Bart Nessux bart_nessux at hotmail.com
Fri Mar 12 21:57:26 CET 2004


Paul Rubin wrote:
> If they have changed the root password on their machine, then the old
> root password in your script won't work on that machine.
> 
> Find another way to do what you're asking.

Well, it works. They change the password and the script changes it 
back... try it yourself on Mac OSX 10.3.x, before claiming it doesn't work.

def set_pass():
    import pexpect
    import time
    # pexpect is an addon module.
    # It has to be installed manually.
    set = r"password"
    child = pexpect.spawn("/usr/bin/passwd")
    child.expect_exact("New password:")
    child.sendline(set)
    time.sleep(0.1)
    child.expect_exact("Retype new password:")
    child.sendline(set)
    time.sleep(0.1)
    child.close()




More information about the Python-list mailing list