rename script to snmp-mac-port and create same /dev/shm files
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Apr 2018 14:47:06 +0000 (16:47 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Apr 2018 14:51:16 +0000 (16:51 +0200)
moved filtering of snmpwalk output into script itself

snmp-grep.sh
snmp-mac-port [new file with mode: 0755]
snmp-walk [deleted file]

index 491a074..8618d18 100755 (executable)
@@ -1,4 +1,4 @@
 #!/bin/sh -xe
 patt=$*
 test -z "$patt" && patt='.'
-grep -r -i $patt /dev/shm/sw.mac.port/ | sed -e 's/^.*snmp.//' -e 's/:[^:]*: / /' -e 's/\].*: / /'
+grep -r -i $patt /dev/shm/sw.mac.port/
diff --git a/snmp-mac-port b/snmp-mac-port
new file mode 100755 (executable)
index 0000000..43e69af
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash -e
+
+. ./snmp.conf # get COMMUNITY
+
+log=/dev/shm/snmp-mac-port
+test -d $log || mkdir $log
+
+snmp_walk() {
+       ip=$1
+       snmpwalk -O0sUX -v2c -Cc -c $COMMUNITY $ip BRIDGE-MIB::dot1dTpFdbPort | sed -e "s/^[^:]*:/$ip/" -e 's/:[^:]*: / /' -e 's/\].*: / /' | tee $log/$ip
+}
+
+if [ ! -z "$1" ] ; then
+       while [ ! -z "$1" ] ; do
+               snmp_walk $1
+               shift
+       done
+       exit 0
+fi
+
+#( ls -d $log.last/* | sed 's/^.*\///' ; ./ips ) | sort -u | while read ip
+./sw-names | while read ip
+do
+       echo "## $ip"
+       snmp_walk $ip
+done
diff --git a/snmp-walk b/snmp-walk
deleted file mode 100755 (executable)
index 4a93344..0000000
--- a/snmp-walk
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash -e
-
-. ./snmp.conf # get COMMUNITY
-
-log=/dev/shm/sw.mac.port
-if [ -e $log.last ] ; then
-       mv -v $log.last $log.last.`ls -d $log.last* | wc -l`
-fi
-test -d $log && mv -v $log $log.last
-mkdir $log
-
-snmp_walk() {
-       ip=$1
-       snmpwalk -O0sUX -v2c -Cc -c $COMMUNITY $ip BRIDGE-MIB::dot1dTpFdbPort | tee $log/snmp.$ip
-       #snmpwalk -v 2c -c $COMMUNITY $ip 1.3.6.1.2.1.17.4.3.1 2>>/dev/shm/sw.errors | tee $log/snmp.$ip
-       #snmpwalk -v 2c -c $COMMUNITY $ip 1.3.6.1.2.1.17.4.3.1.2 2>>/dev/shm/sw.errors | sed 's/iso.3.6.1.2.1.17.4.3.1.2./ /g' | awk '{print $1" .g"$4}' | awk -v sw="$ip" -F '.' '{ printf "%02X:%02X:%02X:%02X:%02X:%02X,%s,%s\n", $1, $2, $3, $4, $5, $6, $7, sw }' | tee $log/$ip
-}
-
-if [ ! -z "$1" ] ; then
-       while [ ! -z "$1" ] ; do
-               snmp_walk $1
-               shift
-       done
-       exit 0
-fi
-
-#( ls -d $log.last/* | sed 's/^.*\///' ; ./ips ) | sort -u | while read ip
-./sw-names | while read ip
-do
-       echo "## $ip"
-       snmp_walk $ip
-done