鸟在笼中,恨关羽不能张飞;Survival of the fittest
分类: LINUX
2015-01-20 16:55:50
直接贴代码了
目前这个环境啥也没有,批量改点东西实在是太费劲,根据以前的改改了,用着还行。
#coding:utf-8
import paramiko,threading,Queue,socket
queue = Queue.Queue()
thread=3
ips=open('ip').readlines()
username='liuxin'
port=58789
pk_path='/Users/liuxin/.ssh/id_rsa'
key=paramiko.RSAKey.from_private_key_file(pk_path)
cmd="df -h"
for ipq in ips:
if ipq.startswith('#'):
continue
queue.put(ipq)
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_system_host_keys()
def sshwork(i,q):
while True:
ip=q.get().strip()
ssh.connect(hostname=ip,username=username,port=port,pkey=key)
stdin, stdout, stderr=ssh.exec_command(cmd)
print stdout.readlines()
q.task_done()
ssh.close()
for i in range(thread):
run=threading.Thread(target=sshwork,args=(i,queue))
run.setDaemon(True)
run.start()
queue.join()