Any memory monitor script?

sprasad
Posts: 24
Joined: Sun Oct 09, 2016 2:52 pm

Any memory monitor script?

Postby sprasad » Sun Oct 09, 2016 3:06 pm

Any memory monitor script?

San
Posts: 24
Joined: Sun Oct 09, 2016 2:53 pm

Re: Any memory monitor script?

Postby San » Sun Oct 09, 2016 3:06 pm

#!/usr/bin/sh
#==========================================================
#
# Description : Script to report processes with more than 2GB Memory utilzation
#==========================================================
# User:root
#==========================================================

#===============================================
# SUB STEP (Define the Function)
#===============================================


send_mail(){
mailx -s "[`hostname`] processes using more than $CEIL kilobytes" $MAILTO <<EOM2

`date`

HOSTNAME = `hostname`
PROCESS ID = $1
PROCESS MEMORY SIZE =$2 Kb

PROCESS INFORMATION:
`cat ${PINFO}`
EOM2
}

#================================================
# STEP010: Setup Initial Parameters and Task Start
#================================================
STEP=STEP010

DATE="date +%x-%X"
PATH=/usr/bin:/usr/sbin:/etc:/usr/contrib/bin/
HOSTNAME=`hostname`
TIME=`date +%H':'%M' '%b' '%d' '%Y`
PID=$$; export PID
ERROR_MSG=""



#//////////////////////////////////
# Change a value.
#//////////////////////////////////

MAILTO="admin@example.com"
CEIL="2000000" # kilobyte
PINFO="/tmp/memory_monitor.out"
PTEMP="/tmp/memory_monitor.tmp"
LINE="10"

#//////////////////////////////////


# temporary file cleanup
> ${PINFO}

UNIX95= ps -e -o ruser,vsz,pid,ppid,args | sort -rnk2 | head -${LINE} > ${PTEMP}
ABEND_CHECK

VSZ=`cat ${PTEMP} | awk '{ print $2 }'`
PROID=`cat ${PTEMP} | awk '{ print $3 }'`

n=1
for i in $VSZ
do
VSZ[$n]=$i
n=`expr $n + 1`
done

n=1
for i in $PROID
do
PROID[$n]=$i
n=`expr $n + 1`
done

n=1
while [ ${n} -le ${LINE} ]
do
if [ ${VSZ[$n]} -gt ${CEIL} ]
then
ps -ef | grep ${PROID[$n]} | grep -v grep > ${PINFO}
ABEND_CHECK
send_mail ${PROID[$n]} ${VSZ[$n]}
fi
n=`expr $n + 1`
done

$NORMALEND

exit 0


Return to “Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest