Solaris Core'd

From Mage
Jump to: navigation, search

This is a quick and dirty script to run through a list of Solaris servers and report machine info like socket numbers and core counts.

vi ~/solcored.sh

##########################################################
#                    Solaris Core'd
#               Last updated: Mar 2, 2016
##########################################################
# Logs into every server and reports sockets/cores.
#
# Prereq: Next to nothing. SSH? Bash?
#
#         If you don't have an ssh key in your ~/.ssh
#         folder this is going to be a looooooooooooooooo
#         oooooooooooooooooooooooooooong process for you.
##########################################################

# Clean up any previous runs...
rm result.txt > /dev/null 2>&1
rm result.csv > /dev/null 2>&1

# If started with the -c flag, output a CSV.
while getopts "c:" option; do
   case $option in
      c) csv=${OPTARG};;
   esac
done

# File containing a list of servers to hit:
list="~/solServerList"

echo "Press CTRL-C to skip a server, CTRL-D to quit the script."
echo ""

if [ -z "$csv" ]; then
#TEXT FILE OUTPUT!

   for thisHereServer in $(< "$list") ; do
      trap "echo CTRL-C was pressed" 2
      trap "echo CTRL-D was pressed" 1

      echo $thisHereServer >>result.txt
      echo "Trying $thisHereServer..."
      ssh $thisHereServer 'echo "Vendor: `sudo dmidecode | grep -i vendor | head -1 | cut -d":" -f2 | cut -c2- | cut -d"," -f1`"; \
         echo "Product Name: `sudo dmidecode | grep -i "Product Name"  | head -1 | cut -d":" -f2 | cut -c2-`"; \
         echo "Model: `cat /proc/cpuinfo | grep "model name" | head -1 | cut -d":" -f2 | tr -s " " | cut -c2-`"; \
         echo "Sockets: `cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l`"; \
         echo "Cores per socket: `egrep -e "core id" -e ^physical /proc/cpuinfo|xargs -l2 echo|sort -u | grep "0 core" | wc -l`"; \
         echo "Total threads: `egrep -e "core id" -e ^physical /proc/cpuinfo|xargs -l2 echo|sort -u | wc -l`"'>>result.txt || \
         echo "Host unreachable." >>result.txt
         echo "" >>result.txt
   done

else
#CSV FILE OUTPUT!

echo "Hostname,Sockets,Cores per Socket,Total threads">result.csv

   for thisHereServer in $(< "$list") ; do
      trap "echo CTRL-C was pressed" 2
      trap "echo CTRL-D was pressed" 1

      echo "Trying $thisHereServer..."
      ssh $thisHereServer 'echo "`hostname`,`psrinfo -p`,`kstat -m cpu_info|grep -w core_id|uniq|wc -l`,`psrinfo|wc -l`" | tr -s " "'>>result.csv || \
      echo "$thisHereServer,Host unreachable." >>result.csv
   done

fi

exit 0