Ho creato un simpatico script che utilizza il protocollo SNMP per estrarre informazioni utili da un elenco di router. Per impostazione predefinita, lo script memorizza i dati in formato CSV in modo che lo si potrà facilmente importare in un foglio di calcolo per l’analisi.
#!/bin/sh
#
# inventory.sh -- a script to extract valuable information
# from a list of routers. (Name, Type, IOS version)
#
#
# Set behaviour
public="home"
workingdir="/home/thomasmilian/temp"
#
LOG=$workingdir/RESULT.csv
infile=$workingdir/RTR_LIST
snmp="/usr/bin/snmpget -v 2c -c $public"
#
while read device
do
$snmp $device sysName.0 > /dev/null
if [ "$?" = "0" ] ; then
rtr=`$snmp $device .1.3.6.1.4.1.9.2.1.3.0 | cut -f2 -d" `
type2=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.3 | cut -f2 -d$ `
ios=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.5 | cut -f2 -d$ `
prot=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.4 | cut -f2 -d$ `
echo "$device, $rtr, $type2, $ios, $prot" >> $LOG
fi
done < $infile