filter log/ filenames into sw.command
[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 >/dev/null
8
9 ping -c 1 $host | grep from > /dev/shm/port.$host.ping
10 ip=`cat /dev/shm/port.$host.ping | cut -d' ' -f5 | tr -d '()':`
11 host=`cat /dev/shm/port.$host.ping | cut -d' ' -f4`
12 mac=`sudo arp -a -n | grep "($ip)" | cut -d' ' -f4 | sort -u`
13 grep -r -i $mac /dev/shm/snmp-mac-port/ | tee /dev/shm/port.$host.switch | cut -d: -f2- | egrep -v '(23|24|48|49)$' # remove trunk ports
14
15 echo "# $host $ip $mac on "`cat /dev/shm/port.$host.switch | cut -d: -f2- | cut -d' ' -f1 | sort -u | wc -l`" switches"