Created
June 1, 2015 06:52
-
-
Save jandahl/52e6e8637b6d41b98acc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
function aboutMe { | |
myName=$(basename "$0") | |
echo -e "\nAlias extruder for RTR hostnames" | |
echo -e "Usage:\n\t$myName countryNumber" | |
echo -e "Example:\n\t$myName 49\n" | |
} | |
function doStuff () { | |
for n in {1..254} | |
do | |
if (( $n % 4 == 2 )) | |
then | |
countryNumber=$1 | |
targetAddress=10.223.$countryNumber.$((n)) | |
remoteHostname=$(snmpget -v 2c -c $snmpPassword $targetAddress iso.3.6.1.2.1.1.5.0 2> /dev/null | awk -F"\"" '{print $2}' | sed 's_.net.dsv.com__') | |
if [[ $remoteHostname == *"RTR"* ]] | |
then | |
echo "alias $remoteHostname='ssh $targetAddress'" | |
fi | |
fi | |
# { hostname=$(echo "alias $(/var/lib/rancid/bin/clogin -c "show start | i hostname" $targetAddress )" | grep -e "^hostname" | sed 's/(\r//g' | sed 's/hostname //g'); echo "alias $(echo $hostname | sed 's/\r//')=\"ssh $targetAddress\""; } | |
done | |
} | |
snmpPassword="insert-your-secret-snmp-stuff-here" | |
if [ -z "$1" ]; then ## Check for args, and if none, show "about" ditty | |
aboutMe | |
exit | |
else | |
doStuff "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment