Skip to content

Instantly share code, notes, and snippets.

@tomoconnor
Created September 3, 2013 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoconnor/6425476 to your computer and use it in GitHub Desktop.
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
#!/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