发布时间:2019-08-30 08:32:16编辑:auto阅读(1830)
公司需要新上项目,上架20台机器,要对这些主机进行改名
#!/usr/bin/env python from multiprocessing import Process, Pool import paramiko import sys,os s = paramiko.SSHClient() s.load_system_host_keys() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) def ssh_run(host_info): ip=host_info[0] username=host_info[1] password=host_info[2] hostname=host_info[3] s.connect(ip,22,username,password,timeout=5) stdin,stdout,stderr=s.exec_command("sed -i '/HOSTNAME/s/localhost\.localdomain/%s/' /etc/sysconfig/network"%hostname) cmd_result = stdout.read(),stderr.read() print '\033[32;1m-------------%s-----------\033[0m' % ip,'Success' for line in cmd_result: print line, p = Pool(processes=2) result_list = [] f = open('ip.txt','r') for line in f.readlines(): new_line=line.strip('\n').split() result_list.append(p.apply_async(ssh_run, [new_line,])) f.close() for res in result_list: res.get() s.close()
cat ip.txt 192.168.10.40 root 123456 web1 192.168.10.35 root 123456 web2
上一篇: python之OS模块(对文件or目录操
下一篇: python的一致性算法hash_rin
47570
45930
36870
34434
29044
25681
24532
19687
19207
17718
5542°
6121°
5654°
5710°
6666°
5450°
5456°
5961°
5936°
7268°