1.Linux下python创建username源码
[root@njmon python]# cat create_user.py
#!/usr/bin/env python
import os
import re
def create_user_func(username,password):
with open('/etc/passwd', 'r') as fd:
for line in fd:
matchusername = re.search(r'%s' % username, line, re.I)
if not matchusername:
os.system('useradd -M -s /sbin/nologin %s -p %s' % (username,password))
print('%s is create successfully' % username)
else:
print('%s is already exists.' % username)
def main():
create_user_func('mysql','wwwwww')
if __name__ == "__main__":
main()
2.创建mysql用户
[root@njmon python]# python create_user.py
mysql is create successfully
3.当mysql用户存在的时候
[root@njmon python]# python create_user.py
mysql is already exists.
版权声明:本文为博主原创文章,未经博主允许不得转载。
Python
- 上一篇:Python创建Linux下文件夹
- 下一篇:Python创建Linux下组



