display status of all switch ports
[dell-switch] / snmp-port-status.sh
1 #!/bin/bash
2
3 # modified from https://gist.github.com/krokodilerian/a88b4ae992706c22e0b0
4 # see /var/lib/snmp/mibs/ietf/IF-MIB
5
6 if [ -z "$1" ]; then
7         echo Usage: "$0" hostname
8         exit 4
9 fi
10
11 sw="$1"
12 . ./snmp.conf
13 snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw"
14
15 numports=`$snmp IF-MIB::ifNumber.0`
16
17 for i in `seq 1 $numports`; do
18         name=`$snmp IF-MIB::ifAlias.$i`
19         if [ "$name" = "No Such Instance currently exists at this OID" ]; then
20                 continue
21         fi
22
23         iftype=`$snmp IF-MIB::ifType.$i`
24
25 #       if [ "$iftype" = "other" ] || [ "$iftype" = propVirtual ] || [ "$iftype" = softwareLoopback ]; then
26 #               continue
27 #       fi 
28         
29         status=`$snmp IF-MIB::ifOperStatus.$i`
30         if [ "$status" = "notPresent" ] ; then
31                 continue;
32         fi
33
34         #descr=`$snmp IF-MIB::ifDescr.$i`
35         speed=`$snmp IF-MIB::ifSpeed.$i | sed 's/000000//'`
36
37 #       echo "## $sw [$name] $iftype $status $descr $speed"
38         echo "$sw $i $speed $status [$name]"
39 done
40