Network device automatically backs up shell scripts

Source: Internet
Author: User


This is the case with the switch as an example of the script written, other manufacturers of equipment according to the device command to modify the script.








Demand



Bulk Backup network device profile to FTP server, and automatically compress the directory where the configuration files are sent to the personal mailbox as an attachment






Environment



Linux Systems: Centos 6.6



Network equipment: CE58/68 switch



IPList file Format: 192.168.1.1:ce6851



192.168.1.2:ce5855






The script reads as follows:



#!/bin/bash



For IP in ' cat/app/backup/iplist '//Read IPList file through for loop



Do



Address= ' echo $IP |awk-f ': ' {print '} '//define variable IP address, use the awk command to ":" To take an IP address for the split symbol



Name= ' echo $IP |awk-f ': ' {print $} '//define variable switch system name



/usr/bin/expect << EOF//Use the expect command to complete interaction with the switch



Spawn ssh-c des-q-o stricthostkeychecking=no [email protected]$address //Start an SSH session



Set Timeout 5



Expect "*password:"



Send "[Email protected]\r"



Expect "*]:"



Send "n\r"



Expect "*>"



Send "FTP ftp_server address\ r"



Expect "none)):"



Send "ftpuser\r"



Expect "*password:*"



Send "[Email protected]\r"



Expect "*ftp]"



Sleep 1



Send "binary\r"



Sleep 1



Expect "*ftp]"



Sleep 1



Send "put vrpcfg.zip ${name}.zip\ r"//modify file name uploaded to FTP server



Sleep 1



Expect "*ftp]"



Sleep 1



Send "quit\r"



Sleep 1



Expect "*>"



Sleep 1



Send "quit\r"



Expect EOF



Eof



Done



time=$ (date "+%y-%m-%d")//define time variable






/usr/bin/zip-r/app/${time}_config.zip/app/ftp/*.zip//Compress the directory where the configuration files are saved on the FTP server



echo "This is Test" | Mail-s "Networkconfig"-a/app/${time}_config.zip ****** @qq. com//through the Mail command to send mail, echo input message content,-s option to configure the message name, the-a option to create an attachment directory



The above is all script content, you can also add the RM command at the end of the script to delete the local profile of the sent message, and then execute the script during the configuration scheduled task cycle.



This script can back up all network device configuration files or issued commands, only need to modify the contents of the expect according to the device.



Network device automatically backs up shell scripts


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.