Wednesday, September 5, 2012

shell script to find linux memory process usage

shell script to find linux memory process usage

Hi,
The following script will check for top 20 processes which uses maximum memory resource in the server and will store it in “overusage” file only if the free memory goes below 700MB. Set cron to execute this script whenever needed.
 
#!/bin/bash
#High RAM usage checker
r=`free -m |awk 'NR==2' |awk '{ print$4 }'`
if [ $r -lt 700 ];
then
ps -e -orss=,args= | sort -b -k1,1n |tail -n 20 >> overusage
exit
fi

No comments:

Post a Comment