Skip to content

Instantly share code, notes, and snippets.

@jandahl
Created November 7, 2014 09:26
Show Gist options
  • Save jandahl/2914c595c3affd7fc833 to your computer and use it in GitHub Desktop.
Save jandahl/2914c595c3affd7fc833 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function basicSetup {
date=$(date +%Y-%m-%d-kl-%H-%m)
snmpCommunityString="snmpstring"
ipTftpServer="10.20.30.40"
targetHostName=$(snmpwalk -v 2c -c $snmpCommunityString $targetHost iso.3.6.1.2.1.1.5.0 | awk -F"\"" '{print $2}' | sed 's_.net.dsv.com__')
outputFileName=/snmp-pushed-configs/$date-$targetHostName-$targetHost.txt
neutralOutputFileName=/snmp-pushed-configs/$targetHostName-$targetHost.txt
snmpCommandString="-c $snmpCommunityString -v 2c $targetHost "
}
function doStuff {
snmpset $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.2.336 i 1 # Set copy protocol to TFTP (1 for TFTP 2 for FTP 4 for SCP 5 for SFTP)
snmpset $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.3.336 i 4 # Set source (3 for startupConfig, 4 for runningConfig)
snmpset $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.4.336 i 1 # set destination type (1 for networkFile)
snmpset $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.5.336 a $ipTftpServer # set IP of destination server
snmpset $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.6.336 s $outputFileName # set filename to write to destination
snmpset $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.14.336 i 1 # Set transfer to active
}
function checkIfTransferIsActive {
isThereAnActiveTransfer=$(snmpget $snmpCommandString 1.3.6.1.4.1.9.9.96.1.1.1.1.14.336 | awk 'NF>1{print $NF}')
if [ $isThereAnActiveTransfer == 1 ]; then
echo "An SNMP-initiated transfer is currently active on $targetHostName ($targetHost) and therefore you cannot push a config to the TFTP server right now."
exit
fi
}
targetHost=$1
basicSetup
checkIfTransferIsActive
doStuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment