Skip to content

Instantly share code, notes, and snippets.

@ggrandes
Last active April 25, 2017 14:49
Show Gist options
  • Save ggrandes/b6af6654fb8f5126db6a to your computer and use it in GitHub Desktop.
Save ggrandes/b6af6654fb8f5126db6a to your computer and use it in GitHub Desktop.
Get Machine Information
#!/bin/bash
# Original Source:
# https://gist.github.com/ggrandes/b6af6654fb8f5126db6a
#
# 2016-02-27, v1, ggrandes
# Get Machine Information
get_machine_info () {
local DEVS DEV_IDS
local UPTIME IDLE
DEVS=(/sys/class/net/eth*)
DEVS=${DEVS[@]/*\/}
DEV_IDS=(${DEVS})
DEV_IDS=${DEV_IDS[@]//[^A-Za-z0-9]/_}
echo hostname=$(hostname -s)
echo cpus=$(grep -cw processor /proc/cpuinfo)
echo mem=$(awk '/MemTotal/ { print $2 }' < /proc/meminfo)
read UPTIME IDLE < /proc/uptime
echo uptime=${UPTIME//\.*}
echo devs_eth=${DEV_IDS// /,}
#
local DEV DEV_ID IP_DEV MAC
for DEV in ${DEVS}; do {
DEV_ID=${DEV//[^A-Za-z0-9]/_}
read MAC < /sys/class/net/${DEV}/address
IP_DEV=($(ip addr show dev $DEV | awk '/inet/ { print $2 }'))
IP_DEV=${IP_DEV[@]/\/*}
echo dev_${DEV_ID}_name=${DEV}
echo dev_${DEV_ID}_mac=${MAC}
echo dev_${DEV_ID}_ips=${IP_DEV// /,}
} done
}
get_machine_info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment