snmp-if-deref.sh 929 Bytes
Newer Older
1
#!/bin/sh
Mike Hibler's avatar
Mike Hibler committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

SNMPGET="/usr/local/bin/snmpget -m CISCO-STACK-MIB:CISCO-PAGP-MIB -Ovq"
community="public"

if [ $# -lt 4 ]
then
    echo "usage: $0 <address> <module> <port> <ifEntry-attribute> [trunk]"
    exit 1
fi

addr=$1
module=$2
port=$3
attr=$4
trunk=$5
    

index=`$SNMPGET $addr $community portIfIndex.$module.$port 2> /dev/null`
if [ $? -eq 0 -a "x$index" != "x" ]
then
    if [ "x$trunk" = "xtrunk" ]
    then
        index=`$SNMPGET $addr $community pagpGroupIfIndex.$index 2> /dev/null`
    fi

    retval=`$SNMPGET $addr $community ifEntry.$attr.$index 2> /dev/null`
    if [ $? -eq 0 -a "x$retval" != "x" ]
    then
	echo $retval
	exit 0
    else
	echo "Error getting ifEntry attribute value: $attr" 1>&2
	exit 1
    fi
else
    echo "Error looking up index for module: $module, port: $port" 1>&2
    exit 1
fi