Skip to content

Instantly share code, notes, and snippets.

@mpontillo
Last active March 4, 2017 00:45
Show Gist options
  • Save mpontillo/ecc30011d6d5889fda23c8e5e3545105 to your computer and use it in GitHub Desktop.
Save mpontillo/ecc30011d6d5889fda23c8e5e3545105 to your computer and use it in GitHub Desktop.
Gathers information about attached hardware and disks.
#!/bin/bash -e
# This script attempts to dump (non-personal) information about the current
# hardware platform. It expects to be run on a modern Linux distribution
# (such as Ubuntu).
DMI_OUTFILE="$(mktemp)"
function finish {
rm -f "$DMI_OUTFILE"
if [ "$1" -gt 0 ]; then
echo "" 1>&2
echo "$0: aborted due to error: $1" 1>&2
fi
}
trap "finish \$?" EXIT
echo "-----BEGIN KERNEL INFO-----"
uname -srm
echo "-----END KERNEL INFO-----"
echo ""
echo "-----BEGIN CPU CORE COUNT AND MODEL-----"
cat /proc/cpuinfo | grep '^model name' | cut -d: -f 2- | sort | uniq -c
echo "-----BEGIN CPU CORE COUNT AND MODEL-----"
if [ -x "$(which lspci)" ]; then
echo ""
echo "-----BEGIN PCI INFO-----"
lspci -nnv
echo "-----END PCI INFO-----"
fi
if [ -x "$(which lsusb)" ]; then
echo ""
echo "-----BEGIN USB INFO-----"
lsusb
echo "-----END USB INFO-----"
fi
echo ""
echo "-----BEGIN MODALIASES-----"
find /sys -name modalias -print0 2> /dev/null | xargs -0 cat | sort | uniq -c
echo "-----END MODALIASES-----"
echo ""
echo "-----BEGIN SERIAL PORTS-----"
find /sys/class/tty/ ! -type d -print0 2> /dev/null \
| xargs -0 readlink -f \
| sort -u
echo "-----END SERIAL PORTS-----"
echo ""
echo "-----BEGIN NETWORK INTERFACES-----"
ip -o link | sed 's/link\/ether ..:..:..:..:..:../link\/ether xx:xx:xx:xx:xx:xx/'
echo "-----END NETWORK INTERFACES-----"
if [ -x "$(which lsblk)" ]; then
echo ""
echo "-----BEGIN BLOCK DEVICE SUMMARY-----"
lsblk
echo "-----END BLOCK DEVICE SUMMARY-----"
fi
if [ "$(id -u)" != "0" ]; then
echo ""
echo "Please run this script as root to gather additional data." 1>&2
exit 0
fi
if [ -x "$(which lsblk)" ]; then
echo ""
echo "-----BEGIN DETAILED BLOCK DEVICE INFO-----"
# Note: excluding ramdisks, floppy drives, and loopback devices.
lsblk --exclude 1,2,7 -d -P
echo ""
for dev in $(lsblk -n --exclude 1,2,7 --output KNAME); do
echo "$dev:"
udevadm info -q all -n $dev
echo ""
echo " size64: $(blockdev --getsize64 /dev/$dev 2> /dev/null || echo unknown)"
echo " bsz: $(blockdev --getbsz /dev/$dev 2> /dev/null || echo unknown)"
done
echo ""
# Enumerate the mappings that were generated (by device).
find /dev/disk -type l | xargs ls -ln | awk '{ print $9, $10, $11 }' | sort -k2
echo "-----END DETAILED BLOCK DEVICE INFO-----"
fi
if [ -x "$(which dmidecode)" ]; then
echo ""
dmidecode -u --dump-bin $DMI_OUTFILE && (
echo "-----BEGIN DMI DATA-----" ;
base64 $DMI_OUTFILE
echo "-----END DMI DATA-----"
) || (echo "Unable to read DMI information."; exit 0)
echo ""
echo "-----BEGIN FULL DMI DECODE-----"
dmidecode -u --from-dump $DMI_OUTFILE
echo "-----END FULL DMI DECODE-----"
# # via http://git.savannah.nongnu.org/cgit/dmidecode.git/tree/dmiopt.c#n142
DMI_STRINGS="
bios-vendor
bios-version
bios-release-date
system-manufacturer
system-product-name
system-version
system-serial-number
system-uuid
baseboard-manufacturer
baseboard-product-name
baseboard-version
baseboard-serial-number
baseboard-asset-tag
chassis-manufacturer
chassis-type
chassis-version
chassis-serial-number
chassis-asset-tag
processor-family
processor-manufacturer
processor-version
processor-frequency
"
echo ""
echo "-----BEGIN DMI KEYPAIRS-----"
for key in $DMI_STRINGS; do
value=$(dmidecode --from-dump $DMI_OUTFILE -s $key)
printf "%s=%s\n" "$key" "$(echo $value)"
done
echo "-----END DMI KEYPAIRS-----"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment