Created
July 23, 2019 18:24
-
-
Save numericillustration/1763004b11350500d4c7b70adec68f8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/bash | |
| GETLDP="/usr/perl5/bin/perl /var/tmp/getldp.pl" | |
| tout=60 | |
| while [[ $# -gt 0 ]]; | |
| do | |
| opt="${1}" | |
| shift | |
| case "$opt" in | |
| "-t" ) tout=${1:-$tout};shift;; | |
| *) | |
| echo "Error: Unknown option '-${opt}'" >&2 | |
| esac | |
| done | |
| ######################################################################################### | |
| ## Find lldp information from each interface | |
| ######################################################################################### | |
| dladm="/usr/sbin/dladm" | |
| svcs="/usr/bin/svcs" | |
| svcadm="/usr/sbin/svcadm" | |
| echo="/usr/bin/echo" | |
| awk="/usr/bin/awk" | |
| serial=`pfexec /usr/bin/sysinfo | /usr/bin/json "Serial Number"` | |
| hostname=`/usr/bin/hostname` | |
| # disable lldp/server, so we can snoop the interface | |
| # without interference from on-board lldp/server | |
| foundenabled=0 | |
| if [ $( ${svcs} -Ho STATE lldp/server )x == "onlinex" ];then | |
| ${svcadm} disable lldp/server | |
| foundenabled=1 | |
| fi | |
| for nic in `${dladm} show-phys -p -o state,link | grep "^up" | awk '{ FS=":"; print $2 }' | sort`;do | |
| MAC=`${dladm} show-phys -m -o address -p ${nic}` | |
| PORTSWITCH=`pfexec ${GETLDP} -l -x -t ${tout} -i ${nic} 2>/dev/null | awk '/^ port-id:/{ ret=0;for (i=2;i<=NF;++i) { if(ret==1) { printf " "};printf $i;ret=1 };printf "," } /^ sysName:/{ printf("%s\n",$2) }'` | |
| #${echo} "${hostname},${nic},${MAC},${PORTSWITCH}" | |
| ${echo} "${serial},${nic},${MAC},${PORTSWITCH}" | |
| done | |
| if [ ${foundenabled} -eq 1 ];then | |
| ${svcadm} enable lldp/server | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment