paramiko+threading批量检查系统状态,paramikothreading,#!/usr/bin/e
文章由Byrx.net分享于2019-03-23 04:03:33
paramiko+threading批量检查系统状态,paramikothreading,#!/usr/bin/e
#!/usr/bin/env python#coding:utf-8import paramikoimport threadingimport os,sys,timedef ssh2(ip,pt,pw,us,comm): try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,port=pt,username=us,password=pw) f.write(('='*20 +'%s status' +'='*20 + '\n')% ip) for COMM in comm: stdin,stdout,stderr = ssh.exec_command(COMM) read = stdout.read() f.write(read) ssh.close()# except SyntaxError:# print "please checking"# sys.exit() except: print "Connection refused" sys.exit()if __name__ == '__main__': print "\033[1;31m 请等待.....\033[0m" open_ip = open('/home/test/iplist.txt') f = open('/home/test/Allsystem.log','w') paramiko.util.log_to_file('/home/test/paramiko.log') up='uptime' df = "df -Ph |awk 'NR == 1 || NR == 6{print $0}'" net="ifconfig |awk 'NR==8'|sed 's/^\s*//g'" command = [up,df,net] for ip in open_ip.readlines(): split = ip.split() name = split[1] ipaddr = split[2] password = split[3] aa = threading.Thread(target=ssh2,args=(ipaddr,22,password,name,command)) aa.start() aa.join() open_ip.close() f.write('='*20 +'All done' +'='*20 + '\n') f.flush() f.close()
相关内容
- python模拟登录v2ex,python模拟v2ex,# coding=utf
- Python抓妹子图+多进程,python抓妹子图,# -*- coding
- Python抓妹子图+多进程,python抓妹子图,# -*- coding
- python线程池进一步认识,python线程池认识,线程池的概念
- python代码实例大小写转换,首字母大写,去除特殊字符,
- python操作mysql数据库代码,pythonmysql数据库,python操作m
- pygame simulate,pygame,import pygam
- python 调用windows api查看系统的电量,pythonapi,通过调用
- 取一列数中连续最长的奇数个数,列数最长奇数个数
- Python实现 深度优先算法生成迷宫,python迷宫, import
评论关闭