saltstack+python+shell批量修改服务器密码
#!/usr/bin/pythonimport commands
ip, host = commands.getstatusoutput("cat hosts|grep -v 'XXX'|awk '{print $2}'")
host_str = host.split('\n')
passwd_str = {}
for i in host_str:
a,b = commands.getstatusoutput('openssl rand 12 -base64')
c,d = commands.getstatusoutput('openssl passwd -1 '+b)
e,f = commands.getstatusoutput("salt "+i+" shadow.set_password XXX '"+d+"'")
passwd_str = b
print f
sts,file = commands.getstatusoutput('touch new_passwd.txt')
if sts == 0:
file_w = open('new_passwd.txt', 'w')
for key in passwd_str.keys():
file_w.write('%s:%s\n' % (key, passwd_str))
file_w.close()
页:
[1]