- 论坛徽章:
- 0
|
本帖最后由 kingsh2012 于 2014-05-11 18:43 编辑
感谢http://blog.chinaunix.net/uid-20569113-id-2793105.html
感谢shell板块里面的大神们帮助,有什么问题,和好的建议帮忙提出,谢谢。
需求介绍
本人管理校园网,当学校大规模停电在来电的时候,有很多交换机会挂掉,还得从新配置交换机,特殊的端口,如一卡通,水电管理都是通过网络传输数据,当网线和端口插错就很麻烦,所以写了个脚本来备份这些交换机配置。
400多台交换机,多种型号。
目录结构
switch/
├─check/
│ cfgfile.sh 读取成功上传配置的IP地址
│ source.sh 读取switch.conf的IP地址
├─errlog/
│ 没有上传配置的交换机生成日志
├─log/
│ 整个备份的过程生成日志
│
│ info.sh 查看备份状况程序
│ run.sh 主备份程序
│ switch.conf 存放IP地址,用户名,密码,配置文件名称
run.sh info.sh
- #!/bin/bash
- #工作目录
- cd /opt/switch/check/
-
- #当前时间
- Daliy="$(date +%Y-%m-%d)"
-
- ./source.sh > 1.txt
- ./cfgfile.sh > 2.txt
-
- sort -n 1.txt > 3.txt
- sort -n 2.txt > 4.txt
-
-
- #成功备份数
- cd /opt/Switch_config_file
- echo "##########################################################"
- echo "总共交换机数"
- awk 'END{print NR}' /opt/switch/switch.conf
-
- echo "成功备份交换机数"
- #ll |grep "^-" | wc -l 其实应该用这个命令查看文件下的文件数
- find ./ -type f | wc -l
- echo "##########################################################"
-
- #文件对比
- cd /opt/switch/check
- echo "备份失败的交换机!"
- comm -3 3.txt 4.txt > /opt/switch/errlog/err_$Daliy.log
- comm -3 3.txt 4.txt
- echo "##########################################################"
-
- #删除.txt文件
- rm -rf *.txt
复制代码 cfgfile.sh
- #!/bin/bash
- #读取TFTP文件夹内的文件
- Folder_A="/opt/Switch_config_file"
- for file_a in ${Folder_A}/*; do
- temp_file=`basename ${file_a%.*}`
- echo $temp_file
- done
复制代码 source.sh
- #/bin/bash
- #工作目录
- #cd /opt/switch/
- file="/opt/switch/switch.conf"
- #执行目录
- while read SW_INFO; do
- SW_IP=`echo $SW_INFO | awk -F"," '{print $2}'`
- (
- echo $SW_IP
- )
- done < $file
复制代码 |
|