read commands from STDIN if used as pipe
[dell-switch] / sw-topology-snmpbulkget.sh
1 #!/bin/sh -e
2
3 # Usage: $0 [sw [oid]]
4
5 dir=/dev/shm/snmp-topology/
6 if [ ! -d $dir ] ; then
7         mkdir $dir
8         ln -sv `pwd`/snmp-topology/.git $dir/
9 fi
10
11 . ./snmp.conf
12
13 ext=""
14 if [ ! -z "$2" ] ; then
15         ext=".$2/"
16         test ! -d "$dir/$ext" && mkdir "$dir/$ext"
17 fi
18
19 ( test ! -z "$1" && echo $1 || ./sw-names ) | xargs -i echo \
20 "test ! -e $dir/{} && " \
21 "snmpbulkwalk -OX -v2c -Cc -c $COMMUNITY {} IF-MIB::ifPhysAddress        | tee -a $dir/{}     && "\
22 "snmpbulkwalk -OX -v2c -Cc -c $COMMUNITY {} Q-BRIDGE-MIB::dot1qTpFdbPort | tee -a $dir/$ext{} || "\
23 "snmpbulkwalk -OX -v2c -Cc -c $COMMUNITY {} BRIDGE-MIB::dot1dTpFdbPort   | tee -a $dir/{} " | sh -x
24
25