#!/bin/bash

DBTIME=5
DBDIR="/exlibris"
EATMIN=256
EATMAX=1024
EATFACTOR=1

ostype=`uname`
arch=`uname -i`
hostn=`hostname`
ipaddr=`grep $hostn /etc/hosts  | awk '{print $1}'`
logfile=./log/`basename $0`.$hostn.log
echo "---------Start--------" > $logfile

LOG() {
   echo $* | tee -a $logfile
}

LOG "----------System Info----------"
LOG "Server Name: $hostn"
LOG "Server Architecture: $arch"
LOG "Server IP: $ipaddr"
vmnic=`dmesg | grep -i vmware | head -1 | awk '{print $1}'`

case "$ostype" in
        'Linux')
		rel=`cat /etc/redhat-release`
		LOG "Linux O/S Version: $rel"
		sysprocnum=`cat /proc/cpuinfo | grep processor | wc -l`
		cores=`cat /proc/cpuinfo | grep "cpu cores" | head -1 | awk '{print $4}'`
		if [ -z $cores ]; then
			cores=1
		fi
		model=`cat /proc/cpuinfo | grep "model name" | head -1 | sed s/"model name"//g | sed s/://g`
		sibl=`cat /proc/cpuinfo | grep sibling | head -1 | awk '{print $3}'`
		if [ -z $sibl ]; then
			sibl=1
		fi
		physproc=$(( $sysprocnum / $sibl ))
		LOG "Total System defined processors: $sysprocnum"
		LOG "Physical Processor Number: $physproc of Model: $model" 
		LOG "Number of Cores per Processor: $cores" 
		LOG "Number of Threads per Core: $sibl" 
		memram=`free -lm | grep Mem | awk '{print $2}'`
		swp=`free -lm | grep Swap | awk '{print $2}'`
		LOG "RAM: $memram MB Swap: $swp MB"
		vmstatus=`ps -ef | grep vmware | grep -v grep | sed s/' '//g`
		if [ $vmstatus ]; then
			LOG "this machine has uses VMware: $vmstatus"
		fi
                ;;      
        'SunOS')
		rel=`uname -rv`
		LOG "Soalris O/S Version: $rel"
		physproc=`psrinfo -p`
		sysprocnum=` psrinfo -v | grep Status | wc -l`
		cores=$(( $sysprocnum / $physproc )) 
		model=`psrinfo -vp | tail -1`
		LOG "Total System defined processors: $sysprocnum"
		LOG "Physical Processor Number: $physproc of Model: $model" 
		LOG "Number of Cores per Processor: $cores" 
		memram=`prtconf | grep Mem | awk '{print $3}'`
		swp=`swap -l | awk '{print $4}' | grep -v "blocks" | xargs | sed s/" "/" + "/g | bc`
		swp=$(( $swp / 2 ))
		swp=$(( $swp / 1024 ))
		LOG "RAM: $memram MB Swap: $swp MB"
		if [ -x `which zoneadm | awk '{print $1}'` ]; then
			zonen=`zonename`
		fi
		LOG "Zonename: $zonen ( non or global means there are no zones)"
                ;;
esac
dbenchname="dbench.$ostype"

if [ $vmnic ]; then
        LOG "This machine probabely is virtual using VMware"
fi

case "$arch" in
        'sparc')
		LOG "32 bit System"
                ;;      
        'i386')
		LOG "32 bit System"
                ;;
        'i686')
		LOG "32 bit System"
                ;;
        'x86_64')
		LOG "64 bit System"
                ;;
esac
