#!/bin/sh ######################################## # Description: This script is used to get system information on x86 and x64 systems. ######################################## #################### # Set variables #################### PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin dmesg_file=/var/run/dmesg.boot dmidecode_file=/var/run/dmidecode.boot ######################### # This function displays the system name. ######################### name() { value=`hostname` echo $value } ######################### # This function displays the operating system. ######################### os() { value=`uname -rs` echo $value } ######################### # This function displays the operating system (full details). ######################### osfull() { os_release=`uname -rs` sysctl -n kern.version | grep -i stable > /dev/null 2>&1 if [ $? -eq 0 ] then release_branch=STABLE else release_branch=RELEASE fi os_arch=`uname -m` case $os_arch in amd64) arch=64-bit ;; i386) arch=32-bit ;; esac syspatch -l > /dev/null 2>&1 if [ $? -eq 0 ] then newest_patch=`syspatch -l | cut -d '_' -f 1 | sort | tail -n 1` value=`echo $os_release'-'$release_branch'-p'$newest_patch' ('$arch' '$os_arch')'` else value=`echo $os_release'-'$release_branch' ('$arch' '$os_arch')'` fi echo $value } ######################### # This function displays the operating system (short). ######################### osshort() { value=`uname -s` echo $value } ######################### # This function displays the chassis tag number. ######################### tag() { sysctl -a | grep hw.vendor > /dev/null 2>&1 if [ $? -eq 0 ] then manufacturer=`sysctl -n hw.vendor` echo $manufacturer | grep -Ei '(Microsoft|VMware)' > /dev/null 2>&1 if [ $? -eq 0 ] then value=Virtual else sysctl -a | grep hw.serialno > /dev/null 2>&1 if [ $? -eq 0 ] then value=`sysctl -n hw.serialno` else value=Unknown fi fi else value=Unknown fi echo $value } ######################### # This function displays the hardware (full details). ######################### hardwarefull() { # CPU cpu_model=`sysctl -n hw.model | sed 's/^ *//;s/ *$//' | sed 's/ */\ /g'` model=`echo $cpu_model` echo $cpu_model | grep Hz > /dev/null 2>&1 if [ $? -eq 1 ] then dmidecode -V > /dev/null 2>&1 if [ $? -eq 0 ] then grep 'No SMBIOS nor DMI' $dmidecode_file > /dev/null 2>&1 if [ $? -eq 1 ] then cpuspeed=`sed -n '/, DMI type 4,/,/^\s*$/p' $dmidecode_file | sed -r 's/^[[:space:]]+//' | grep '^Current Speed:' | uniq | awk '{print $3}'` if [ $cpuspeed -lt 1000 ] then cpuspeed_pretty=`echo $cpuspeed'MHz'` else cpuspeed_ghz=$(echo "scale=2; $cpuspeed / 1000" | bc) cpuspeed_pretty=`echo $cpuspeed_ghz'GHz'` fi else cpuspeed=`sysctl -n hw.cpuspeed` if [ $cpuspeed -lt 1000 ] then cpuspeed_pretty=`echo $cpuspeed'MHz'` else cpuspeed_ghz=$(echo "scale=2; $cpuspeed / 1000" | bc) cpuspeed_pretty=`echo $cpuspeed_ghz'GHz'` fi fi fi cpu_model=`echo $model @ $cpuspeed_pretty` fi logical_cpus=`sysctl -n hw.ncpu` grep '^cpu.*: smt ' $dmesg_file > /dev/null 2>&1 if [ $? -eq 0 ] then physical_cpus=`grep '^cpu.*: smt ' $dmesg_file | uniq | cut -d : -f 2- | cut -d , -f 1 | uniq | wc -l` cores_per_cpu=$((`grep '^cpu.*: smt ' $dmesg_file | uniq | cut -d : -f 2- | cut -d , -f 2 | awk '{print $2}' | sort | tail -n 1` + 1)) threads_per_cpu=$(($logical_cpus / $physical_cpus)) else physical_cpus=1 cores_per_cpu=1 threads_per_cpu=1 fi if [ "$threads_per_cpu" -gt "$cores_per_cpu" ] then hyper_threading="Yes" else hyper_threading="No" fi cpu_value=`echo CPU: Model: $cpu_model, Hyper-Threading: $hyper_threading, Physical CPU\'s: $physical_cpus, Cores per CPU: $cores_per_cpu, Threads per CPU: $threads_per_cpu, Logical CPU\'s: $logical_cpus` # RAM dmidecode -V > /dev/null 2>&1 if [ $? -eq 0 ] then grep 'No SMBIOS nor DMI' $dmidecode_file > /dev/null 2>&1 if [ $? -eq 1 ] then ram_data_width=`sed -n '/, DMI type 17,/,/^\s*$/p' $dmidecode_file | sed -r 's/^[[:space:]]+//' | grep '^Data Width:' | head -n 1 | awk '{print $3}'` ram_total=`sed -n '/, DMI type 17,/,/^\s*$/p' $dmidecode_file | sed -r 's/^[[:space:]]+//' | sed -n '/^Data Width: '$ram_data_width'/,/^Size:/p' | grep ^Size: | awk '{s+=$2} END {print s}'` if [ $ram_total -lt 1024 ] then ram_total_pretty=`echo $ram_total' MB'` else ram_total_gb=$(echo "scale=0; $ram_total / 1024" | bc) ram_total_pretty=`echo $ram_total_gb' GB'` fi manufacturer=`sysctl -n hw.vendor` echo $manufacturer | grep -Ei '(Microsoft|VMware)' > /dev/null 2>&1 if [ $? -eq 0 ] then ram_modules_installed=Virtual ram_module_speed=Virtual else ram_modules_installed=`sed -n '/, DMI type 17,/,/^\s*$/p' $dmidecode_file | sed -r 's/^[[:space:]]+//' | sed -n '/^Data Width: '$ram_data_width'/,/^Size:/p' | grep ^Size: | wc -l` ram_module_speed=`sed -n '/, DMI type 17,/,/^\s*$/p' $dmidecode_file | sed -r 's/^[[:space:]]+//' | grep ^Speed: | uniq | head -n 1 | awk '{print $2,$3}'` fi else ram_total_b=`sysctl -n hw.physmem` ram_total=$(echo "scale=0; $ram_total_b / 1024 / 1024" | bc) if [ $ram_total -lt 1024 ] then ram_total_pretty=`echo $ram_total' MB'` else ram_total_gb=$(echo "scale=0; $ram_total / 1024" | bc) ram_total_pretty=`echo $ram_total_gb' GB'` fi ram_modules_installed=Unknown ram_module_speed=Unknown fi else ram_total_pretty=Unknown ram_modules_installed=Unknown ram_module_speed=Unknown fi ram_value=`echo RAM: Total installed: $ram_total_pretty, Modules installed: $ram_modules_installed, Module speed: $ram_module_speed` echo $cpu_value echo $ram_value } ######################### # This function displays the chassis. ######################### chassis() { sysctl -a | grep hw.vendor > /dev/null 2>&1 if [ $? -eq 0 ] then manufacturer=`sysctl -n hw.vendor` echo $manufacturer | grep -Ei '(Microsoft|VMware)' > /dev/null 2>&1 if [ $? -eq 0 ] then value=Virtual else value=`echo $manufacturer` fi else value=Unknown fi echo $value } ######################### # This function displays the model. ######################### model() { sysctl -a | grep hw.vendor > /dev/null 2>&1 if [ $? -eq 0 ] then manufacturer=`sysctl -n hw.vendor` echo $manufacturer | grep -Ei '(Microsoft|VMware)' > /dev/null 2>&1 if [ $? -eq 0 ] then value=Virtual else sysctl -a | grep hw.product > /dev/null 2>&1 if [ $? -eq 0 ] then product_name=`sysctl -n hw.product` else product_name=Unknown fi sysctl -a | grep hw.version > /dev/null 2>&1 if [ $? -eq 0 ] then version=`sysctl -n hw.version` else version=Unknown fi value=`echo $product_name $version` fi else value=Unknown fi echo $value } ######################### # This is the main part of the script. ######################### uid=`id -u` if [ $uid -ne 0 ] then echo You must be the root user to run this script. exit 0 else if [ $# -ne 1 ] then echo usage: system_info.sh [option] echo echo " name Displays system name" echo " os Displays operating system" echo " osfull Displays operating system (full details)" echo " osshort Displays operating system (short)" echo " tag Displays chassis tag number" echo " hardwarefull Displays hardware (full details)" echo " chassis Displays chassis" echo " model Displays model" exit 0 else case $1 in name) name ;; os) os ;; osfull) osfull ;; osshort) osshort ;; tag) tag ;; hardwarefull) hardwarefull ;; chassis) chassis ;; model) model ;; *) echo Unknown option ;; esac fi fi exit 0