python 添加用户设置密码并发邮件给root用户
#!/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())
以上所述是小编给大家介绍的python 添加用户设置密码并发邮件给root用户的全部叙述,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16