发布时间:2017-12-02 17:41:43编辑:Run阅读(3785)
python3脚本代码如下
# !/usr/bin/python
# -.- coding: utf-8 -.-
__author__ = 'www.py3study.com'
import getpass
import os
class user_and_password(object):
def __init__(self):
self.run()
def run(self):
with open('/etc/passwd', 'r') as fp:
ss = fp.readlines()
user_info = ''.join(ss)
if 'itadmin' in user_info:
print(u'*********itadmin帐号已存在**************')
print(r'\\\\\\\\\更改itadmin密码////////////')
with open('/root/itadmin_passwd.txt', 'r') as fp:
pw_read = fp.read().strip('\n')
'''echo itadmin:itadmin123123 | chpasswd'''
os_passwd_one = 'echo itadmin:' + pw_read + ' | chpasswd'
print(os_passwd_one)
os.system(os_passwd_one)
print(u'------------itadmin更改后的密码为:{}------------'.format(pw_read))
fp.close()
else:
print(u'**********创建itadmin帐号****************')
os.system('useradd itadmin')
with open('/root/itadmin_passwd.txt', 'w') as fp:
fp.write('itadmin')
fp.close()
with open('/root/itadmin_passwd.txt', 'r') as fp:
pw_read = fp.read().strip('\n')
print(u'------------itadmin初始密码为:{}------------'.format(pw_read))
os_passwd = "echo itadmin:" + pw_read + " | chpasswd"
print(os_passwd)
os.system(os_passwd)
fp.close()
if __name__ == '__main__':
st = user_and_password()
chmod +x 给上权限运行
应该看到的结果
上一篇: vsftp本地配置
下一篇: nginx拒绝某个ip访问
47605
45985
36909
34469
29080
25713
24566
19714
19245
17756
5565°
6155°
5691°
5737°
6705°
5483°
5484°
5988°
5965°
7295°