Python adds a user password and sends an email to the root user, pythonroot
#! /Usr/bin/env python # coding: utf8import osimport sysimport mkpasswd // previously written. directly call 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 _ nam E _ = "_ main _": if len (sys. argv )! = 2: print ("Usage:./useradd. py username") else: adduser (sys. argv [1], mkpasswd. mkpasswd ())
The above section describes how to add a password for a python user and send an email to the root user. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in time!