zoukankan      html  css  js  c++  java
  • paramiko交换机巡检

    #-*- coding:UTF-8 -*-
    import paramiko
    import time
    starttime = time.strftime('%Y-%m-%d %T')
    start_info = "巡检开始时间:"+str(starttime)
    cmd_filepath = r"d:Pythonpyxunjiancmd.txt"
    cmd_file = open(cmd_filepath,"r")
    cmds = cmd_file.readlines()
    dev_filepath = r"d:Pythonpyxunjiandevice_info.txt"
    dev_file = open(dev_filepath,"r")
    while 1: 
       dev_info = dev_file.readline()
       if not dev_info :
           break
       else :
           devs = dev_info.split(',') 
           ip = devs[0]
           username = devs[1]
           password = devs[2].strip()
           password = password.strip('
    ')
           ssh = paramiko.SSHClient()
           ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
           ssh.connect(hostname = ip,username = username,password = password)
           print("成功连接",ip)
           command = ssh.invoke_shell()
           time.sleep(3)
           command.send('N
    ') #该行非必须
           command.send('screen-length 0 temporary
    ') #取消分屏显示
           for cmd in cmds:
           command.send(cmd+'
    ')
           time.sleep(5)
           output = command.recv(65535).decode()
           log = open(r"d:Pythonpyxunjian\"+ip+".txt",'a')
           endtime = time.strftime('%Y-%m-%d %T')
           end_info = "巡检结束时间:"+str(endtime)
           log.write(start_info+'
    
    '+output+'
    
    '+end_info)
           log.close()
    dev_file.close()
    
    #巡检命令文档cmd.txt
    display device
    display environment
    display alarm urgen
    display memory-usage
    display cpu-usage
    display logbuffer level 0
    display logbuffer level 1
    display logbuffer level 2
    display logbuffer level 3
    display logbuffer level 4
    #设备信息 device_info.txt
    192.168.10.11,admin,Huawei@123
    192.168.10.12,admin,Huawei@123
    192.168.10.13,admin,Huawei@123
    192.168.10.14,admin,Huawei@123
    
  • 相关阅读:
    LOJ6274 数字
    test20200415 看门人 和 WC2010 重建计划
    TJOI2018 Party 和 HDU4352 XHXJ's LIS
    LOJ3228 Tree Depth
    AGC026D Histogram Coloring
    LOJ3277 星座 和 BZOJ2616 PERIODNI
    LOJ2331 某位歌姬的故事 和 CF1327F AND Segments
    AGC024F Simple Subsequence Problem
    LOJ3278 收获
    LOJ3282 治疗计划
  • 原文地址:https://www.cnblogs.com/kylingx/p/13258844.html
Copyright © 2011-2022 走看看