From: Dobrica Pavlinusic Date: Fri, 22 Jun 2018 10:17:19 +0000 (+0200) Subject: find switch port for specified hostname X-Git-Url: http://git.rot13.org/?p=dell-switch;a=commitdiff_plain;h=c1d915b281bc9a5a9efb977ef2a4441aec56fe0b;ds=sidebyside find switch port for specified hostname --- diff --git a/find-port-for-hostname b/find-port-for-hostname new file mode 100755 index 0000000..f9f8c89 --- /dev/null +++ b/find-port-for-hostname @@ -0,0 +1,13 @@ +#!/bin/sh -e + +host=$1 + +test -z "$host" && echo "Usage: $0 hostname" && exit 1 + +sudo id + +ping -q -c 1 $host +mac=`sudo arp -a | grep $host | cut -d' ' -f4 | sort -u` +grep -r -i $mac /dev/shm/snmp-mac-port/ | tee /dev/shm/port.$host | egrep -v '(23|24|48|49)$' # remove trunk ports + +echo "# "`cat /dev/shm/port.$host | cut -d: -f2- | cut -d' ' -f1 | sort -u | wc -l`" switches have $host mac $mac"