CPU Core and Thread Count Script (Linux, Solaris, AIX & macOS)

What does it do?

Checks Solaris, Linux, AIX and macOS for CPU Core/Thread Counts. The AIX portion had not been tested in quite awhile. I no longer have access to an AIX platform.

core_count.sh


p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3b2322; background-color: #d7d3b7} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Courier; color: #3b2322; background-color: #d7d3b7; min-height: 17.0px} span.s1 {font-variant-ligatures: no-common-ligatures} span.Apple-tab-span {white-space:pre}
#!/bin/sh
#
#This script is used to count the number of cores for the following OS platforms: AIX, Linux, Solaris, Mac OS X
# Updated: 040121
# Author: Andy Dishong


## Set varibles
host=`uname -n`
os=`uname -s`


##Print usage information


##Validate root or root access




# Check to see if running root
PROG=`basename $0` ; export PROG


if [ “${LOGNAME}” = “root” ]
then    # Success
        :
else    # exit – Not root
        echo “${PROG}: You must be Root use “su” or “sudo” to use script!”
        exit 1
fi
##Location of logs
CORE_INSTALL_DIR=/var/tmp/cores          
if [ ! -d $CORE_INSTALL_DIR ] ; then
  mkdir -p $CORE_INSTALL_DIR/logs
fi


CORE_LOGDIR=$CORE_INSTALL_DIR/logs
export CORE_INSTALL_DIR CORE_LOGDIR






##Verify command(s)
#
#Linux
linux () {
echo “Number of cores for: OS=$os HOST=$host”
cat /proc/cpuinfo | grep -i ‘processor’ | wc -l
lshw -C processor
}
#lshal???
#Parse /proc/cpu ???


#Solaris
#machdep.cpu.core_countSolaris
solaris () {
echo “Number of cores for: OS=$os HOST=$host”
psrinfo -p #core count system wide
psrinfo -v #verbose output
}


#Aix
aix () {
echo “Number of cores for: OS=$os HOST=$host”
lsattr -El sys0 |grep ent_cap |awk {‘print $2’} #breaks out by LPAR?
}


#Mac OS X (because you can)
osx () {
core=`sysctl hw.ncpu | awk ‘{print $2}’`
# or
# sysctl hw.ncpu
echo “Number of cores for: OS=$os HOST=$host are: $core”
echo “OS=$os HOST=$host | core count=$core” >>$CORE_LOGDIR/core_count-`date “+%y%m%d%H%M%S”`  2>&1

}


##Identify platform type
if [ $os = “linux” ]; then
linux
elif [ $os = “sunos” ]; then
solaris
elif [ $os = “aix” ]; then
aix
elif [ $os = “Darwin” ]; then
osx
else
echo “No compatible platform found for OS=$os HOST=$host”
exit 1
fi


##Count socket


##Count cores


##Print information