#!/bin/bash
#pid=$(ps -ef | grep tomcat | grep -v grep | awk '{print $2}')
#pid=$(ps -ef | grep tomcat | grep -v grep | awk '{print $2}')
#echo "tomcat的pid为$TomcatID"
#d_today=$ date "+%Y-%m-%d %H%M%S"
d_today=`date '+%Y-%m-%d %H:%M:%S'`
pid=$(curl -I -m 10 -o /dev/null -s -w %{http_code} http://www.qq.com)
if [$pid -eq 200]; then
echo "tomcat pid is $pid at${d_today}"
echo "tomcat pid is $pid at${d_today}/n">>/data/webbak/task_shell/shelllog/tomcat.txt
#if [$pid]; then
#cd /data/mysoft/apache-tomcat-8.5.11/bin && ./startup.sh
# rm -rf /data/mysoft/apache-tomcat-8.5.11/work
#echo 'Unitop@19866'|sudo -S /data/mysoft/apache-tomcat-8.5.11/bin/startup.sh
#echo "tomcat is stop at${d_today}/n">>/data/webbak/task_shell/shelllog/tomcat.txt
echo "tomcat is stop at${d_today}"
else
/data/mysoft/apache-tomcat-8.5.11/bin/startup.sh
echo "tomcat is stop at${d_today}/n">>/data/webbak/task_shell/shelllog/tomcat.txt
#kill -9 $pid
#echo kill is ok
fi
发现了一个问题就是单独执行这个脚本能关闭、启动tomcat放到crontab里面定时执行就不行了。
解决办法:
在catalina.sh里面加入jdk和jre的路径,配环境:
这样放到crontab是执行成功了的