从网上找了一段,写得挺麻烦,但可以借一下思路
cat watch.sh
#!/bin/sh
cd /root/bin
PID=`ps -aef | grep Xms500M | grep -v grep | gawk '{print $2}'`
PID=`expr $PID + 1 - 1`
date
free
echo $PID
echo "------------------"
if [ $PID -eq 0 ]
then
sleep 10
/usr/java/tomcat/bin/startup.sh
sleep 160
fi
while [ 1 ]
do
date
free
echo "Tomcat process ID is $PID"
wget http://192.168.1.101/jsp/w_blog/blog.jsp -O working.jpg 2>> /dev/null &
sleep 120
touch working.jpg
SIZE=`du working.jpg | gawk '{print $1}'`
if [ $SIZE -le 20 ]
then
WID=`ps -aef | grep 192.168.1.101 | grep -v grep | gawk '{print $2}'`
WID=`expr $WID + 1 - 1`
if ! test -z $WID
then
killall wget
fi
echo "Tomcat restart checking"
free
vmstat
FREEMEM=`free | grep Mem | gawk '{print $4}'`
if [ $FREEMEM -le 15000 ]
then
if [ $PID -ne 0 ]
then
kill -9 $PID
ls -l
/usr/java/tomcat/bin/shutdown.sh
fi
/usr/java/tomcat/bin/shutdown.sh
sleep 10
/usr/java/tomcat/bin/startup.sh
sleep 30
fi
date
ps -aef | grep -v httpd
ls -l
PID=`ps -aef | grep Xms500M | grep -v grep | gawk '{print $2}'`
PID=`expr $PID + 1 - 1`
fi
rm -f working.jpg
done
posted on 2008-03-24 19:25
liunix 阅读(1294)
评论(0) 编辑 收藏