huawei交换机配置备份

华为交换机配置备份

yum install expect

vim backup-config.sh

#!/bin/bash
backdir=/var/lib/tftpboot
DATE=$(date +%Y%m%d)
backup="$backdir/$DATE"
if [ ! -d $backup ]; then
    mkdir $backdir/$DATE
fi
while read line;do
        fping $line > /dev/null
        sleep 1
        if [ $? -eq 0 ];then
                expect ./backup-expect.exp $line >>./backup_$DATE.log
        mv $backdir/aaa.zip $backup/"$line".zip
                echo $line >> ./online-ip.log
        else
 
                echo $line >> ./offline-ip.log
        fi
done < ./device.txt
cd $backdir
zip -r $DATE.zip $DATE
sz $DATE.zip

vim backup-exp.exp

#!/usr/bin/expect
set ipaddr [lrange $argv 0 0]
set timeout 5
spawn telnet $ipaddr
expect "Username:"
send "admin\r"
expect "Password:"
send "admin\r"
expect "*>"
send "save\r"
expect "*]"
send "y\r"
set timeout -1
expect "*>"
send "tftp -a $ipaddr 192.168.1.20 put vrpcfg.zip aaa.zip\r"
set timeout -1
expect "*>"
send "quit\r"
expect eof

 

posted @ 2020-05-13 10:40  Me-lihu  阅读(12)  评论(0编辑  收藏  举报