检测tomcat进程脚:tomcatMonitor.sh
#!/bin/sh
tomcatName=tomcat3
tomcatPath=/tomcat/tomcat3
selfName=tomcatMonitor
pid=`ps aux | grep $tomcatName | grep -v grep | grep -v $selfName | awk '{print $2}'`
echo $pid
if [ "$pid" -lt -1 ]; then
{
echo ===========shutdown================
$tomcatPath/bin/shutdown.sh
sleep 3
pid=`ps aux | grep $tomcatName | grep -v grep | grep -v $selfName | awk '{print $2}'`
if [ -n "$pid" ]
then
{
sleep 3
echo ========kill tomcat begin==============
echo $pid
kill -9 $pid
echo ========kill tomcat end==============
}
fi
sleep 3
echo ===========startup.sh==============
$tomcatPath/bin/startup.sh
}
else
echo ========== $tomcatName is running ===============
fi
添加可执行权限
#chmod 775 tomcatMonitor.sh
crond配置每5分钟检测一次
#crontab -e
*/5 * * * * su - root -c /root/tomcatMonitor.sh
使配置生效
#service crond stop
#service crond start
#!/bin/sh
tomcatName=tomcat3
tomcatPath=/tomcat/tomcat3
selfName=tomcatMonitor
pid=`ps aux | grep $tomcatName | grep -v grep | grep -v $selfName | awk '{print $2}'`
echo $pid
if [ "$pid" -lt -1 ]; then
{
echo ===========shutdown================
$tomcatPath/bin/shutdown.sh
sleep 3
pid=`ps aux | grep $tomcatName | grep -v grep | grep -v $selfName | awk '{print $2}'`
if [ -n "$pid" ]
then
{
sleep 3
echo ========kill tomcat begin==============
echo $pid
kill -9 $pid
echo ========kill tomcat end==============
}
fi
sleep 3
echo ===========startup.sh==============
$tomcatPath/bin/startup.sh
}
else
echo ========== $tomcatName is running ===============
fi
添加可执行权限
#chmod 775 tomcatMonitor.sh
crond配置每5分钟检测一次
#crontab -e
*/5 * * * * su - root -c /root/tomcatMonitor.sh
使配置生效
#service crond stop
#service crond start