linux 非交互普通用户修改密码

 1 import pexpect
  2 newpasswd = 'www.baoyiluo.com'
  3 oldpasswd = 'www.longgeek.com'
  4 child = pexpect.spawn('passwd')
  5 child.expect('(current).*:')
  6 print 'old over'
  7 child.sendline(oldpasswd)
  8 child.expect('New password.*:')
  9 child.sendline(newpasswd)
 10 print 'first'
 11 child.expect('Retype new password.*:')
 12 child.sendline(newpasswd)
 13 print 'second'

你可能感兴趣的:(linux)