Add LLDP information on Absolute Manage on Mac OS X

The script below¬†can be used to show LLDP information on Absolute Manage for Mac OS X clients. To make the script working, it’s necessary first to compile the OpenLLDP tool. This step is documented in another post on this blog. You can simply add this script to a new Custom Information Field in Absolute Manage and assign to all computers.

#!/bin/bash
#adminsys.ch - FTBZ - 12.09.2012

## Check if lldpd is installed and start it
if [ ! -f /usr/local/sbin/lldpd ]; then
	/bin/echo "lldpneighbors is not installed on this computer."
	exit
else
	/usr/local/sbin/lldpd > /dev/null 2>&1
	/bin/sleep 35
fi

ETHERNET=`networksetup -listallnetworkservices | grep -m 1 Ethernet`

if [ "$ETHERNET" == "" ]; then
	/bin/echo "Unable to determine the ethernet interface."
	exit
fi

IP_ADDRESS=`/usr/sbin/networksetup -getinfo $ETHERNET | grep -v IPv6 | grep -m 1 "IP address:" | awk '{print $3}'`

if [ "$IP_ADDRESS" == "" ]; then
	/bin/echo "Unable to determine the IP address."
	exit
fi

## Query lldpneighbors
SWITCH=`/usr/local/bin/lldpneighbors | grep "System Name: " | awk -F " " '{print $3}'`
PORT=`/usr/local/bin/lldpneighbors | grep "Port Description: " | awk -F " " '{print $3}'`

if [ "$PORT" == "" ]; then
	/bin/echo "Unable to determine the network location."
	exit
fi

## Stop the lldp daemon (because the software is in alpha)
/usr/bin/killall lldpd

## Show the results
/bin/echo "$SWITCH - $PORT"
exit

This script was tested only with Mac OS X 10.7 and OS X 10.8.

Leave a Reply

Your email address will not be published. Required fields are marked *

*