#!/usr/bin/env python

#coding: utf8
import os
import sys
import mkpasswd       //这是之前写的,直接调用
import string
content = """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())