[mrtg] Re: script problem
Justin Shore
listuser at vinnie.ksu.ksu.edu
Sun Feb 20 06:45:55 MET 2000
At 10:31 AM +0100 2/19/00, Alex van den Bogaerdt wrote:
>You need to filter out the error message. You can do so by checking
>the first character:
>
>[alex at home]$ snmpget router public 4.21.1.2.10.2.2.2
>Error in packet.
>Reason: There is no such variable name in this MIB.
>This name doesn't exist:
>ip.ipRoutingTable.ipRouteEntry.ipRouteIfIndex.10.2.2.2
>
>[alex at home]$ snmpget router public 4.21.1.2.10.2.2.1
>ip.ipRoutingTable.ipRouteEntry.ipRouteIfIndex.10.2.2.1 = 3
>
>As you can see, valid route entries start with "ip" whereas invalid answers
>return "This name...."
>
>If your snmpget does it different, I'm sure you can find a similar approach.
>
> > [mrtg at ipgate bin]$ cat get-dynamic-port
>
>[...]
>
> > PORT=`$SNMPCMD $HOST $COMMUNITY $GET_PORT.$TARGET |awk '{print $3}'`;
>
>This line fails if the IP address doesn't exist. You could change it
>into
>PORT=`$SNMPCMD $HOST $COMMUNITY $GET_PORT.$TARGET |awk '/^ip/{print $3}'`
>to filter out the garbage.
>
>Then check for an empty $PORT and echo 0:
>
>if [ -z "$PORT" ]
>then
> echo 0
>else
> # rest of script
>fi
>
Alex,
Thanks for the reply. Unfortunately its still not working.
Here's where I'm at now:
HOST="$1"
COMMUNITY="$2"
TARGET="$3"
SNMPCMD="/usr/local/bin/snmpget"
GET_PORT="ip.ipRouteTable.ipRouteEntry.ipRouteIfIndex"
GET_IN="interfaces.ifTable.ifEntry.ifInOctets"
GET_OUT="interfaces.ifTable.ifEntry.ifOutOctets"
GET_UPTIME="system.sysUpTime.0"
PORT=`$SNMPCMD $HOST $COMMUNITY $GET_PORT.$TARGET |awk '/^ip/{print $3}'`
UPTIME=`$SNMPCMD $HOST $COMMUNITY $GET_UPTIME |awk '{print $5,$6, $7}'`;
if [ -z "$PORT" ]
then
# ok, so I want it to print 0's if the string is null.
echo 0;
echo 0;
echo "$UPTIME";
echo "$HOST";
else
# otherwise get $IN and $OUT and print it all.
IN=`$SNMPCMD $HOST $COMMUNITY $GET_IN.$PORT |awk '{print $3}'`;
echo "$IN";
OUT=`$SNMPCMD $HOST $COMMUNITY $GET_OUT.$PORT |awk '{print $3}'`;
echo "$OUT";
echo "$UPTIME";
echo "$HOST";
fi
Its still printing that out error out to the screen when I run it by
hand on a port that I know doesn't exist. I'm not great at stderr
and all that. Is there a way to trap it?
Justin
--
Justin Shore
K-State Linux Distro Mirror, Sysadmin
macdaddy at vinnie.ksu.ksu.edu
<http://vinnie.ksu.ksu.edu/mirror/rpm2html>
<ftp://vinnie.ksu.ksu.edu/pub/mirror/linux>
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Help mailto:mrtg-request at list.ee.ethz.ch?subject=help
Archive http://www.ee.ethz.ch/~slist/mrtg
More information about the mrtg
mailing list