发布时间:2017-12-02 17:41:43编辑:Run阅读(3699)
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访问
47303
45507
36587
34101
28810
25424
24274
19469
18914
17483
5304°
5904°
5403°
5488°
6376°
5220°
5219°
5731°
5687°
6996°