参考文献
http://www.open-open.com/news/view/1c0179b
http://blog.jobbole.com/52060/
按照这个博客,实现获取多台服务器的空间使用情况
代码如下:
#!/usr/bin/env python2.7 #-*- coding:utf-8 -*- from multiprocessing.dummy import Pool as ThreadPool import subprocess import time results = [] ip_list = [ip.strip() for ip in open(‘./ssd‘,‘r‘)] def getsize(host): now = time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(time.time())) print host,now command = "df -h" sys_cmd = """ssh -n -f -i /usr/home/guosong/.ssh/id_rsa -p 26387 -o StrictHostKeyChecking=no -o ConnectTimeout=2 root@‘%s‘ \"%s\" """ %(host,command) pipe = subprocess.Popen(sys_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,stdin=subprocess.PIPE) stdout,stderr = pipe.communicate() #print stdout results.append(stdout) pool = ThreadPool(4) pool.map(getsize,ip_list) pool.close() pool.join()