Swap Monitoring Script

#!/usr/bin/ksh
### Checks swap space and check whether swap configured properly.
printf "\n\n\n\n"
echo "-------------------------------------------------------"
echo "Sever Name : `hostname`"
echo "-------------------------------------------------------"
echo "Physical `/usr/sbin/prtconf | grep Mem`"
SWAP_SIZE_USED=`swap -s|nawk '{print substr($9,1,length($9)-1)}'`
SWAP_FREE=`swap -s|nawk '{print substr($11,1,length($11)-1)}'`
(( SWAP_PER_USE = SWAP_SIZE_USED * 100 / (SWAP_FREE + SWAP_SIZE_USED) ))
(( GB = SWAP_SIZE_USED / 1024 ))

swap -l| grep -v swaplo | awk 'BEGIN {TOT=0}{TOT=TOT+$4} END {print "Physical Swap size : "TOT/2/1024" Megabytes"}'

echo "SWAP Utilization is currently : ${SWAP_PER_USE}% ($GB Megabytes)"

niviswaptot=`swap -l| grep -v swaplo | awk 'BEGIN {TOT=0}{TOT=TOT+$4} END {print "Physical Swap size : "TOT/2/1024" Megabytes"}'|awk '{print
$5}'`
niviphytot=0
niviphytot=`/usr/sbin/prtconf | grep Mem|awk '{print $3}'`
(( niviphytot = niviphytot * 2 ))
echo "Total swap space allocation should be two times the amount of memory."
if [ ${niviswaptot} -ge ${niviphytot} ]; then
echo "-----------> Swap configured properly"
else
echo "-----------> Swap not configured properly"
fi
echo "-------------------------------------------------------\n\n\n"
exit 0



Output :

-------------------------------------------------------
Sever Name : Mural
-------------------------------------------------------
Physical Memory size: 768 Megabytes
Physical Swap size : 2047.98 Megabytes
SWAP Utilization is currently : 34% (769 Megabytes)
Total swap space allocation should be two times the amount of memory.
-----------> Swap configured properly
-------------------------------------------------------

To display the Process name and its Memory Information- Solaris

#!/bin/sh

/usr/bin/printf "%-6s %-9s %s\n" "PID" "Total" "Command"
/usr/bin/printf "%-6s %-9s %s\n" "---" "-----" "-------"

for PID in `/usr/bin/ps -e | /usr/bin/awk '$1 ~ /[0-9]+/ { print $1 }'`
do
CMD=`/usr/bin/ps -o comm -p $PID | /usr/bin/tail -1`
# Avoid "pmap: cannot examine 0: system process"-type errors
# by redirecting STDERR to /dev/null
TOTAL=`/usr/bin/pmap $PID 2>/dev/null | /usr/bin/tail -1 | \
/usr/bin/awk '{ print $2 }'`
[ -n "$TOTAL" ] && /usr/bin/printf "%-6s %-9s %s\n" "$PID" "$TOTAL" "$CMD"
done | /usr/bin/sort -nr -k2

Vxvm script for Display Disk Group with Volume Information

Script :

#!/usr/bin/ksh
vxprint | grep Disk |awk {'print $3'} | grep -v rootdg >/var/tmp/dgname
printf "\n......................................................................\n"
printf "Server Name : "
hostname
cat /var/tmp/dgname | while read dgnames
do
printf "......................................................................\n"
printf "\nDiskGroup Name : $dgnames "
vxprint -g $dgnames | grep ^dm |awk 'BEGIN {TOT=0} {TOT=TOT+$5} END{print " Total Size of the DG=" TOT/2/1024" MB ("TOT/2/1024/1024" GB)\n"}'
vxprint -g $dgnames | grep ^v | awk '{print "Volume : " $2" " $5/2/1024 " MB (" $5/2/1024/1024 "GB)"}'
printf "\nAvailable space in $dgnames = "
vxassist -g $dgnames maxsize| awk '{print $5}'
done
printf "......................................................................\n"


Output :

......................................................................
Server Name : SolarisVM
......................................................................

DiskGroup Name : datadg Total Size of the DG=415733 MB (405.989 GB)

Volume : Bla_vg 100 MB (0.0976562GB)
Volume : Datavol 102400 MB (100GB)
Volume : WEB 15360 MB (15GB)
Volume : fvol 73728 MB (72GB)
Volume : insvol 76800 MB (75GB)
Volume : spare 6144 MB (6GB)

Available space in datadg = (2945Mb)
......................................................................

DiskGroup Name : unixdg Total Size of the DG=173636 MB (169.567 GB)

Volume : exp 30720 MB (30GB)

Available space in unixdg = (142915Mb)
......................................................................