Created
September 3, 2013 15:30
-
-
Save tomoconnor/6425476 to your computer and use it in GitHub Desktop.
Neat little script I wrote to copy the running-config from a Cisco router using SNMP and TFTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##### You will need the CISCO-CONFIG-COPY-MIB File from ftp://ftp.cisco.com/pub/mibs/v2/CISCO-CONFIG-COPY-MIB.my ##### | |
##### You will also need to set the value of TFTP_IP | |
export MIBDIRS=~/mibs | |
echo $MIBDIRS | |
export MIBS=CISCO-CONFIG-COPY-MIB | |
export IPADDR=$1 | |
export HOSTNAME=$2 | |
export COMMUNITY=$3 | |
if [ $# -ne 3 ] | |
then | |
echo "Incorrect number of arguments passed" | |
exit 2 | |
fi | |
if [ -z $1 ] | |
then | |
echo "IP Address (arg 1) is not set" | |
exit 1 | |
fi | |
if [ -z $2 ] | |
then | |
echo "Hostname (arg 2) is not set" | |
exit 1 | |
fi | |
if [ -z $3 ] | |
then | |
echo "Community(arg 3) is not set" | |
exit 1 | |
fi | |
export TFTP_IP="192.168.254.253" | |
echo $CLEAN_HOSTNAME | |
snmptable -v2c -c${COMMUNITY} $IPADDR ccCopyTable | |
snmpset -v2c -c${COMMUNITY} $IPADDR \ | |
ccCopyProtocol.23 i tftp \ | |
ccCopySourceFileType.23 i runningConfig \ | |
ccCopyDestFileType.23 i networkFile \ | |
ccCopyServerAddress.23 a ${TFTP_IP} \ | |
ccCopyFileName.23 s ${HOSTNAME}_$(date +%s).conf | |
snmptable -v2c -c${COMMUNITY} $IPADDR ccCopyTable | |
snmpset -v2c -c${COMMUNITY} $IPADDR ccCopyEntryRowStatus.23 i active | |
echo "Waiting...." | |
sleep 10 | |
snmptable -v2c -c${COMMUNITY} $IPADDR ccCopyTable|grep successful | |
snmpset -v2c -c${COMMUNITY} ${IPADDR} ccCopyEntryRowStatus.23 i destroy | |
echo "$HOSTNAME sucessfully backed up" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment