Linux hardware details.

2011-11-28 533 words 3 mins read

Here is one of the scripts that I found on the net while searching for something … Note the URL for the script in the Description.

#!/bin/bash -
#===============================================================================
#
#          FILE:  linux_hw.sh
#
#         USAGE:  ./linux_hw.sh
#
#   DESCRIPTION:  http://www.howtogeek.com/howto/solaris/get-the-processor-type-on-solaris/
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 09/13/2011 03:57:34 PM IST
# Last modified: Sun Oct 30, 2011  04:59PM
#      REVISION:  ---
#===============================================================================

function linux_hw_CPU {
	typeset num=0
	typeset name=""
	typeset cores=""
	name="$( cat /proc/cpuinfo | awk -F: '
/vendor_id/ { vendor=$2 }
/model name/ { model=$2 }
/cpu MHz/ {
if( model ~ "Hz" ) {speed=""} else { speed=$2? MHz" };
print vendor, model, speed; }
		' | tail -1
	)"

        num=$(if [ -r /proc/vmware/cpuinfo ]; then awk '/pcpu/ { print NF-1 }' /proc/vmware/cpuinfo; else cat /proc/cpuinfo | grep processor| wc -l; fi)

	# ESX: mas info sobre logical/cores/packages
	if [ -r /proc/vmware/sched/ncpus ]
	then
		cores=$( echo $( cat /proc/vmware/sched/ncpus ) )
	fi

	echo $num $( echo "$name ($cores)" | enclose )
}

function enclose {
	tr -s " " | sed -e "s/^/\"/; s/$/\"/; s/\"\ /\"/; s/\ \"/\"/"
}

function linux_hw_CPU {

	typeset num=0
	typeset name=""
	typeset cores=""

	name="$(
		cat /proc/cpuinfo | awk -F: '
/vendor_id/ { vendor=$2 }
/model name/ { model=$2 }
/cpu MHz/ {
if( model ~ "Hz" ) {speed=""} else { speed=$2" MHz" };
print vendor, model, speed; }
		' | tail -1
	)"

	num=$(
		if [ -r /proc/vmware/cpuinfo ]
		then
			awk '/pcpu/ { print NF-1 }' /proc/vmware/cpuinfo
		else
			cat /proc/cpuinfo | grep processor| wc -l
		fi

	)

	if grep -q "physical id" /proc/cpuinfo || grep "siblings" /proc/cpuinfo
	then
		chip_count=$( grep "physical id" /proc/cpuinfo | sort -u | wc -l )
		chip_core=$( grep "siblings" /proc/cpuinfo | tail -1 | cut -d: -f2 )
		cores="($chip_count chips x $chip_core cores)"
	fi

	# Blades HP con
	if [ -x /sbin/hpasmcli ]
	then
		chip_name=$( /sbin/hpasmcli -s "SHOW SERVER" | grep "Name" | head -1 | cut -d: -f2 )
		chip_speed=$( /sbin/hpasmcli -s "SHOW SERVER" | grep "Speed" | head -1 | cut -d: -f2 )
		chip_core=$( /sbin/hpasmcli -s "SHOW SERVER" | grep "Core" | head -1 | cut -d: -f2 )
	fi

	# ESX: mas info sobre logical/cores/packages
	if [ -r /proc/vmware/sched/ncpus ]
	then
		cores="($( echo $( cat /proc/vmware/sched/ncpus ) ))"
	fi

	# Linux Itanium IA64
	if grep -q -i itanium /proc/cpuinfo
	then
		name="$(
		grep "vendor" /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep "arch " /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep "family" /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep "cpu MHz" /proc/cpuinfo | cut -d: -f2- | cut -d. -f1 | tail -1 ) Mhz"

		chip_count=$( grep "physical id" /proc/cpuinfo | sort -u | wc -l )
		chip_core=$( grep "siblings" /proc/cpuinfo | tail -1 | cut -d: -f2 )
		cores="($chip_count chips x $chip_core cores)"
	fi

	echo $num $( echo "$name $cores" | enclose )
}

linux_hw_CPU
Enhanced by Zemanta

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it