#!/bin/ksh

### This is a script which will monitor the system and will tell you the
### processes using the highest CPU and memory utilization in a very readable
### format.
###
### Submitted By: Gaurav Syal
###

date
PLAT=`uname -s`
echo "-------------------------------------------------------------------------"

tput smso
echo "                        Top Processes                              "
tput rmso
  /usr/bin/uname -a
  /usr/bin/uptime
  /usr/bin/date

echo "-------------------------------------------------------------------------"

if [ "$PLAT" = "SunOS" ]
then
        /usr/ucb/ps -aux|head -5
else
	if [ "$PLAT" = "AIX" ]
	then
        /usr/bin/ps -aux|head -5
	else
		echo " This platform is not supported"
	fi
fi

echo " "
echo "-------------------------------------------------------------------------"
echo                    "\t\t\t\t `tput smso`     SAR     `tput rmso`"

/usr/sbin/sar 1 5 | head -4
/usr/sbin/sar 1 5 | grep -i Average
echo " "
echo "-------------------------------------------------------------------------"
echo                    "\t\t   `tput smso`     Highest Memory Utilization      `tput rmso`"
echo "PID      USER  VSZ    COMMAND  "
/usr/bin/ps -eo pid,user,vsz,args | grep -v %CPU | sort -nbk 3 | tail -5

echo "-------------------------------------------------------------------------"

echo "-------------------------------------------------------------------------"
echo                    "\t\t   `tput smso`     Highest CPU Utilization      `tput rmso`"
echo " PID     USER %CPU COMMAND      "
/usr/bin/ps -eo pid,user,pcpu,args | grep -v %CPU |  sort -nbk 3 | tail -25

echo "-------------------------------------------------------------------------"

echo "-------------------------------------------------------------------------"
echo                    "\t\t\t   `tput smso`     SWAP INFO      `tput rmso`"

if [ "$PLAT" = "SunOS" ]
then
	tot=`/usr/sbin/swap -s | sed 's:k::g'|awk '{print ($9+$11)/1024 "MB"}'`
	fin=`/usr/sbin/swap -s | sed 's:k::g'|awk '{print $9/($9+$11) * 100}'`
	echo "Total Paging Space                Percent Used "
	echo "$tot                              $fin%"
else
	if [ "$PLAT" = "AIX" ]
	then
		/usr/sbin/lsps -s
	else
		echo " This platform is not supported"
	fi
fi
echo "-------------------------------------------------------------------------"

exit 0;


##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed. 
###
###
### Copyright 2006 Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### http://www.sun.com/bigadmin/common/berkeley_license.html
##############################################################################


