发布时间:2017-12-02 17:41:43编辑:Run阅读(3836)
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访问
47744
46234
37109
34626
29228
25885
24744
19862
19415
17907
5715°
6314°
5834°
5887°
6983°
5829°
5845°
6360°
6315°
7672°