Skip to content

Instantly share code, notes, and snippets.

@davlgd
Created August 14, 2023 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davlgd/d7194efe6c01096a9d4b5ac084d74cd8 to your computer and use it in GitHub Desktop.
Save davlgd/d7194efe6c01096a9d4b5ac084d74cd8 to your computer and use it in GitHub Desktop.
This script retrieves and displays information about the system's CPU, motherboard, and memory through DMI Decode
#!/bin/bash
display_help() {
echo "Usage: $0 [option]"
echo
echo "This script retrieves and displays information about the system's CPU, motherboard, and memory through DMI Decode."
echo
echo "Options:"
echo " --help Display this help message and exit."
echo
echo "To run this script on a remote server with a root account, use:"
echo "ssh USER@SERVER_IP 'bash -s' < $0"
exit 1
}
strip_value() {
awk -F: '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//'
}
if [[ "$1" == "--help" ]]; then
display_help
fi
# Check if the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Retrieve the CPU details
cpu_details=$(dmidecode -t processor | grep "Version:" | strip_value)
cpu_signature=$(dmidecode -t processor | grep "Signature:" | strip_value)
cpu_id=$(dmidecode -t processor | grep "ID:" | strip_value)
# Display the CPU information
echo "CPU:"
echo "- Reference: $cpu_details"
echo "- Signature: $cpu_signature"
echo "- ID: $cpu_id"
echo
# Retrieve the motherboard details
motherboard_details=$(dmidecode -t baseboard | grep "Product Name:" | strip_value)
motherboard_serial=$(dmidecode -t baseboard | grep "Serial Number:" | strip_value)
# Retrieve the BIOS details
bios_version=$(dmidecode -t bios | grep "Version:" | strip_value)
bios_release_date=$(dmidecode -t bios | grep "Release Date:" | strip_value)
bios_runtime_size=$(dmidecode -t bios | grep "Runtime Size:" | strip_value)
bios_rom_size=$(dmidecode -t bios | grep "ROM Size:" | strip_value)
# Display the motherboard & BIOS information
echo "Motherboard:"
echo "- Reference: $motherboard_details"
echo "- Serial Number: $motherboard_serial"
echo "- BIOS: $bios_version ($bios_release_date, $bios_runtime_size on $bios_rom_size)"
echo
# Retrieve and display information for each memory module
echo "Memory:"
dmidecode -t memory | awk -F: '
/Size:/ && $2 !~ /No Module Installed/ {size = $2}
/Type:/ {type = $2; gsub(/^ /, "", type)}
/Locator:/ {locator = $2}
/Form Factor:/ {form_factor = $2}
/Manufacturer:/ {manufacturer = $2}
/Configured Memory Speed:/ {speed = $2; print_info()}
function print_info() {
if (size != "") {
print "-"locator":"size" ("type","form_factor","speed") from"manufacturer;
size = ""; type = ""; locator = ""; speed = ""; form_factor = ""; manufacturer = "";
}
}' | sed 's/^[ \t]*//;s/[ \t]*$//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment