python3 pexpect 自动交互修改linux系统密码
#!/usr/bin/python3 import pexpect new_pw = '12345678' try: process = pexpect.spawn('passwd',timeout=5) process.expect('[Nn]ew') process.sendline(new_pw) process.expect('[Rn]etype') process.sendline(new_pw) process.expect('[Ss]uccess.*') print('ACK') except: print('NAK')