paramiko+threading批量检查系统状态
发布时间:2020-05-24 23:33:52 所属栏目:Python 来源:互联网
导读:paramiko+threading批量检查系统状态
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 #!/usr/bin/env python
#coding:utf-8
import paramiko
import threading
import os,sys,time
def 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 " 33[1;31m 请等待..... 33[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()
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
