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
-------------------------------------------------------