查看交换机配置文件的位置(需开启SCP功能:scp server enable)
第一部分:(脚本主体)#!/bin/bash
# 设备配置备份
net_list=/opt/net_bak_work/net_ip_list
cat ${net_list} | while read line
do
host_list=$(echo $line | awk '{print $1}' )
name_list=$(echo $line | awk '{print $2}' )
# linux_dir
src_file='flash:/startup.cfg'
# windows_dir
# src_file='flash:\startup.cfg'
dest_file=/opt/net_bak_work/$(date "+%Y%m%d")/
mkdir -p ${dest_file}${name_list}
expect -f net_bak.expect "$host_list" "$name_list" "$src_file" "$dest_file"
done
# 企业微信机器人通知
if
[ $? -eq 0 ];then
bak_file_num=$(find /opt/net_bak_work/$(date "+%Y%m%d")/ -name startup.cfg | wc -l)
wx_bot_api='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=******************'
curl ${wx_bot_api} -H "Content-Type: application/json" -d "{\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"<font color=info>Net-Device's Config Files Backed Up Successfully \nAnd the Backed files number is</font> <font color="warning">$bak_file_num</font> \n<font color=info>[Bakfile_address_url](http://172.16.40.201/netbak)</font> \nFrom: <font color=comment>$(date "+%Y_%m_%d-%H:%M:%S")</font>\"}}"
else
curl ${wx_bot_api} -H "Content-Type: application/json" -d "{\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"<font color="warning">Net-Device's Config Files Backed Up Error</font>\nPleases Check it\n[Bakfile_address_url](http://172.16.40.201/netbak)\nFrom: <font color=comment>$(date "+%Y_%m_%d-%H:%M:%S")</font>\"}}"
fi
2810





