From: Dobrica Pavlinusic Date: Wed, 11 Apr 2018 14:47:06 +0000 (+0200) Subject: rename script to snmp-mac-port and create same /dev/shm files X-Git-Url: http://git.rot13.org/?p=dell-switch;a=commitdiff_plain;h=9396b238ef41c8896115bed4675066d5d2510c4d;hp=cf2a51aa94bf9ecba2fdba6e30dfbc74ef6f0bad rename script to snmp-mac-port and create same /dev/shm files moved filtering of snmpwalk output into script itself --- diff --git a/snmp-grep.sh b/snmp-grep.sh index 491a074..8618d18 100755 --- a/snmp-grep.sh +++ b/snmp-grep.sh @@ -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 index 0000000..43e69af --- /dev/null +++ b/snmp-mac-port @@ -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 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