Linux下查看tomcat内存状况并执行重启命令

iamplane 2010-10-15

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
export JAVA_HOME=/usr/java/jdk1.6.0_13
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
export LANG=en_US.UTF-8
ram_max=25
pid_ram=`ps -ef | grep java| grep -v "grep"|awk '{print $2}'|xargs|awk '{print $1}'`
ram=`ps -e -o 'user,pid,%cpu,%mem,vsz,rss,tty,stat,start,time,command' |grep java|grep -v grep |awk '{print $4}'|xargs|awk '{print $1}'`
#echo $pid_ram
#echo $ram
#echo $ram_max
if(echo $ram $ram_max | awk '!($1>$2){exit 1}')
then
#echo 1
kill -9 $pid_ram
sleep 2
cd /usr/java/tomcat5.5/bin
\./startup.sh
fi
 

相关推荐