码迷,mamicode.com
首页 > 编程语言 > 详细

Python备份H3C交换机配置并上传到tftp

时间:2020-01-20 14:52:47      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:send   实验   col   time()   oca   ESS   man   环境   log   

实验环境:

centos7

python3

pip3 install netmiko

1. python脚本

import time
from netmiko import ConnectHandler

now = time.strftime("%Y%m%d", time.localtime(time.time()))
log_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

ip_list = [
    [SW-101,10.255.224.254],
    [SW-102,10.255.224.101],
    [SW-103,10.255.224.102],
    [SW-104,10.255.224.103],
    [SW-105,10.255.224.104],
    [SW-106,10.255.224.105],
    [SW-107,10.255.224.106],
]
SW = {
    device_type:hp_comware,
    ip:‘‘,
    username:admin,
    password:password,
}

for ip_item in ip_list:
    SW[ip] = ip_item[1]
    connect = ConnectHandler(**SW)
    print(log_time +   Successfully connected to  + ip_item[0])
    save_commands = save\n + y\n + \n + y\n
    output = connect.send_command(save_commands)
    backup_commands = tftp 10.255.224.13 put startup.cfg  + ip_item[0] + / + ip_item[0] + - + now +.cfg
    result = connect.send_command(backup_commands)

2. vim /etc/crontab

#每天0点执行备份脚本
00
00 * * * root /root/python/backup_sw/backup1.py >> /root/python/backup_sw/backup1.log

Python备份H3C交换机配置并上传到tftp

标签:send   实验   col   time()   oca   ESS   man   环境   log   

原文地址:https://www.cnblogs.com/starbaba/p/12217741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!