find-port-for-* /dev/shm/trunk.regex auto generation
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 Dec 2018 11:35:03 +0000 (12:35 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 8 Jan 2019 08:07:53 +0000 (09:07 +0100)
find-port-for-hostname
find-port-for-mac [new file with mode: 0755]
shm-trunk.regex [new file with mode: 0644]

index 81bf56a..d053193 100755 (executable)
@@ -6,6 +6,8 @@ test -z "$host" && echo "Usage: $0 hostname" && exit 1
 
 sudo id >/dev/null
 
+. ./shm-trunk.regex
+
 # hide physical and trunk ports (> 10 mac, port nr <= 49)
 cat /dev/shm/snmp-mac-port/* | cut -d' ' -f1,4 | sort | uniq -c | awk '{ if ( $1 > 10 && $3 <= 49 ) print "/"$2":"$2 " .* " $3 }' > /dev/shm/trunk.regex
 
diff --git a/find-port-for-mac b/find-port-for-mac
new file mode 100755 (executable)
index 0000000..de8838b
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh -e
+
+test -z "$1" && echo "Usage: $0 d4:ca:6d:01:4c:f2" && exit 1
+
+mac=$1
+
+. ./shm-trunk.regex
+
+grep -r -i $mac /dev/shm/snmp-mac-port/ | tee /dev/shm/mac.$mac | grep --file /dev/shm/trunk.regex -v | cut -d: -f2-
+echo "# mac $mac on "`cat /dev/shm/mac.$mac | cut -d: -f2- | cut -d' ' -f1 | sort -u | wc -l`" switches"
diff --git a/shm-trunk.regex b/shm-trunk.regex
new file mode 100644 (file)
index 0000000..b2e9466
--- /dev/null
@@ -0,0 +1,2 @@
+# hide physical and trunk ports (> 10 mac, port nr <= 49)
+cat /dev/shm/snmp-mac-port/* | cut -d' ' -f1,4 | sort | uniq -c | awk '{ if ( $1 > 10 && $3 <= 49 ) print "/"$2":"$2 " .* " $3 }' > /dev/shm/trunk.regex