Skip to content

Instantly share code, notes, and snippets.

@adamrb
Last active December 13, 2015 22:09
Show Gist options
  • Save adamrb/4982876 to your computer and use it in GitHub Desktop.
Save adamrb/4982876 to your computer and use it in GitHub Desktop.
Parsing RedHat System Information via SSH
#!/bin/bash
host=$1
ssh $host 'bash -s' <<'ENDSSH'
model=$(dmidecode | grep 'Product Name' | cut -d ':' -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')
echo "System Info"
echo "---------------"
echo "Model Name: $model"
echo
echo "CPU Info"
echo "---------------"
echo "Model Name: $(grep 'model name' /proc/cpuinfo | sort | uniq | cut -d ':' -f2 | sed 's/^[ \t]*//;s/[ \t]*$//;s/ */ /g')"
echo -n "Physical CPUs: "
cpus=$(grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l)
echo $cpus
echo -n "Cores per CPU: "
cores=$(grep 'cores' /proc/cpuinfo | sort | uniq | cut -d ':' -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')
echo $cores
echo "Total Processing Cores: $(echo $cores \* $cpus | bc)"
echo -n "Total Threads (including HT): "
threads=$(grep 'processor' /proc/cpuinfo | wc -l)
echo $threads
echo
IFSBAK=$IFS
IFS="
"
echo "Memory Info"
echo "----------------"
# Don't use the "--type" if it's RHEL4
if cat /etc/redhat-release | grep -q "release 4"; then
echo "Sorry, I can't get this easily for RHEL4. It's $(date +%Y), time to upgrade your OS. ;)"
else
#This doesn't seem to be accurate
#echo -n "Max Memory: "
#total=0 && for size in $(dmidecode --type memory | grep "Maximum Capacity" | awk '{print $3}');do total=$(echo $total + $size | bc); done && echo "$total GB"
echo -n "Installed Memory: "
total=0 && for size in $(dmidecode --type memory | grep "Size" | grep -v "No Module Installed" | awk '{print $2}');do total=$(echo $total + $size | bc); done && echo "$(echo $total / 1024 | bc ) GB"
echo -n "Total Memory Slots: "
total=0 && for size in $(dmidecode --type memory | grep "Number Of Devices" | awk '{print $4}');do total=$(echo $total + $size | bc); done && echo $total
echo -n "Memory Type:"
dmidecode --type memory | sed 's/^[ \t]*//;s/[ \t]*$//;s/ */ /g' | grep "^Type:" | sort -u | cut -d ":" -f 2-
echo -n "Memory Speed: "
dmidecode --type memory | sed 's/^[ \t]*//;s/[ \t]*$//;s/ */ /g' | grep "^Speed:" | sort | cut -d ":" -f 2- | uniq -c | sed 's/^[ \t]*//;s/[ \t]*$//;s/ */ /g' | awk '{ print $2,$3}'
echo "Memory Size(s): "
for i in $(dmidecode --type memory | egrep -e "[[:space:]]+Size:" | cut -d ":" -f 2- | sort | uniq -c | sed 's/^[ \t]*//;s/[ \t]*$//;s/ */ /g' | dmidecode --type memory | egrep -e "[[:space:]]+Size:" | cut -d ":" -f 2- | sort | uniq -c | sed 's/^[ \t]*//;s/[ \t]*$//;s/ */ /g' | awk '{ print $2,$3,"("$1")"}'); do echo -e "\t$i"; done
fi
IFS=$IFSBAK
echo
echo "Disk Info"
echo "---------------"
hpacucli ctrl all show config | grep -e "array" -e "logicaldrive" -e "physicaldrive"
echo
echo "Software Information"
echo "---------------"
echo -n "Operating System: "
cat /etc/redhat-release
ENDSSH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment