Created
April 27, 2018 11:02
-
-
Save velenux/7faf9cfd5c8d5fa325ebd691cbeeb8e4 to your computer and use it in GitHub Desktop.
print the relevant hardware information about the network interfaces
This file contains 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
#!/bin/bash | |
# show all the relevant hardware information from network interfaces | |
for DEV in /sys/class/net/* ; do | |
dev_name=$(basename "${DEV}") | |
echo "# $dev_name =========================================" | |
hardware_path=$(udevadm info --query=path --path=${DEV} 2>&1) | |
if [ -z "$hardware_path" ]; then | |
echo "Could not find the hardware path, skipping." | |
continue | |
fi | |
if [[ $hardware_path =~ "virtual" ]]; then | |
echo "It's a virtual device, skipping." | |
continue | |
fi | |
# FIXME: this is horrifying but path length varies | |
# so we have to work from the end of the string | |
pci_address=${hardware_path%/*} | |
pci_address=${pci_address%/*} | |
pci_address=${pci_address##*/} | |
pci_address=${pci_address#*:} | |
pci_name=$(lspci 2>&1 | grep "^$pci_address") | |
if [ -z "$pci_name" ]; then | |
pci_name="Could not find the PCI name" | |
fi | |
link_detected=$(ethtool ${dev_name} | grep -i "Link detected" | awk {'print $3'}) | |
if [ -z "$link_detected" ]; then | |
link_detected="no" | |
fi | |
# report our findings | |
echo "PCI name: $pci_name" | |
echo "Hardware path: $hardware_path" | |
echo "Link detected: $link_detected" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment