#!/usr/bin/env python
#coding: utf8import osimport sysimport mkpasswd //这是之前写的,直接调用import stringcontent = """username: ${user}password: ${password}"""t = string.Template(content)def adduser(username, pwd): os.system("useradd %s" % username) os.system("echo %s | passwd --stdin %s" % (pwd, username)) os.system("echo -e '%s' | mail -s 'user info' root" % \ (t.substitute(user=username, password=pwd)) )if __name__ == "__main__": if len(sys.argv) != 2: print ("Usage: ./useradd.py username") else: adduser(sys.argv[1], mkpasswd.mkpasswd())