f9f8c892a29af18ef1ae63350b07c61d5b7e8f1f
[dell-switch] / find-port-for-hostname
1 #!/bin/sh -e
2
3 host=$1
4
5 test -z "$host" && echo "Usage: $0 hostname" && exit 1
6
7 sudo id
8
9 ping -q -c 1 $host
10 mac=`sudo arp -a | grep $host | cut -d' ' -f4 | sort -u`
11 grep -r -i $mac /dev/shm/snmp-mac-port/ | tee /dev/shm/port.$host | egrep -v '(23|24|48|49)$' # remove trunk ports
12
13 echo "# "`cat /dev/shm/port.$host | cut -d: -f2- | cut -d' ' -f1 | sort -u | wc -l`" switches have $host mac $mac"