09-28-2005
25,
0
Join Date: Aug 2005
Last Activity: 12 June 2007, 11:14 AM EDT
Posts: 25
Thanks Given: 0
Thanked 0 Times in 0 Posts
Need help with script
I am attempting to write a script that will capture a runaway java process on our server, which occasionally reaches 99%. I am using the following script.
#!/usr/bin/ksh
jobname="manu_process_watch.sh"
dirname=/opt/manu/mdiap1/scripts
export HOST=`hostname`
filename="${HOST}_`date +%y%m%d`.dat"
ps -aefd -F pid=Process,pcpu=CPU_Use,time=CPU_Time,vsz=Memory,runame=User,args=Command | sort -r +1 | cut -c -130| head -20 > $filename
if test ! -f $dirname/$filename ; then
echo
echo "File $dirname/$filename not found."
echo
fi
process="Java"
command=`grep java $dirname/$filename | cut -f7 -d " "`
pid=`grep java $dirname/$filename | cut -f2 -d " "`
cpupct=`grep java $dirname/$filename | cut -f3 -d " "`
cputime=`grep java $dirname/$filename | cut -f4 -d " "`
numrows=`grep java $dirname/$filename | wc -l`
if [ $cpupct > 90 ] ; then
send an email
fi;
-----------------------------------------------------
This script could potentially yield multiple rows. How can I alter the script so that I only send the email when the cpupct of any of the rows is greater than a certain percentage?