471,337 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Change User Password using Python on openBSD

Dear All,

I started using Python just a few days back and there was a requirement of an assigned project to change the user Password through script without user interaction. I could write the following peace of code, which uses Pexpect for the same. The mentioned Poc may certainly help others, incase they need some requirement like this.

import pexpect, sys

if len(sys.argv) != 3:
print "Usage: "+sys.argv[0]+" user new_password."
sys.exit(1)
(user, password) = (sys.argv[1], sys.argv[2])

child = pexpect.spawn('passwd %s' %user)
child.expect('New password:')
child.sendline(password)
child.expect('Retype new password:')
child.sendline(password)

print child.before
child.expect(pexpect.EOF)


Rgds,
Geo :)
Sep 10 '07 #1
0 1795

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Noah | last post: by
9 posts views Thread by YouCanCallMeAl | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.