Posts Tagged bash

How to get CPU information under Linux

Posted by on Tuesday, 7 February, 2012

From time to time I have the need to get basic CPU information out of a server.
There are several tricks available online (like this one and this other one) but I decided to write a small bash script that would spit all this information on a easy to read format.
A friend of mine mentioned that he saw this before somewhere but the writing of the script was a nice exercise.

PHYSICAL=`grep -i "physical id" /proc/cpuinfo | sort -u | wc -l`
LOGICAL=`grep -i "processor" /proc/cpuinfo | sort -u | wc -l`
CORES=`grep -i "cpu cores" /proc/cpuinfo|head -1|awk '{print $4}'`
grep -i "^flags" /proc/cpuinfo|head -1|grep " ht ">/dev/null
if [ $? -eq 0 ] ; then HT="YES" ; else HT="NO"; fi
SIBLINGS=`grep siblings /proc/cpuinfo |head -1 |awk '{print $3}'`
if [ $SIBLINGS -gt $CORES ] ; then HTACTIVE="YES" ; else HTACTIVE="NO" ; fi
echo "Physical CPUs : $PHYSICAL"
echo "Logical CPUs : $LOGICAL"
echo "Cores per CPU : $CORES"
echo "Spport for HT : $HT"
echo "Siblings : $SIBLINGS"
echo "Is HT active : $HTACTIVE"