相信不少用Tomcat作web容易的开发者都知道,Tomcat运行久了之后,会崩溃掉,而且原有的关闭和启动脚本并不能使用,由于端口仍然占用。所以须要作几件事: html
function check_port(){ echo "Begin checking..." # exist process occupying port 80 if lsof -i :80 | grep -q ${pattern} then proc=`lsof -i :80 | grep ${pattern} | awk '{print $1}'` # get process name pid=`lsof -i :80 | grep ${pattern} | awk '{print $2}'` # get process id echo "Exist process ${proc} with id ${pid} occupying port 80..." kill -9 ${pid} echo "Killed it!" else echo "No process occupying port 80..." fi }上面这个方法就是作这件事情,而后写出restartup.sh的脚本。
tlog=/Tomcat-Home/bin/tlog DATE=`date +'%F %T'` check=`/usr/bin/wget -S --spider --tries=3 --timeout=3 http://ip:port/status.html 2>&1 | grep HTTP/1.1|awk '{print $2}'` if [ "$check"x = "200"x ];then echo "$DATE good state">>$tlog else echo "$DATE bad state.">>$tlog restartup.sh fi测试上述脚本,得出statusCheck.sh脚本
*/5 * * * * /Tomcat-Home/bin/statusCheck.sh
crontab job.txt使用-l参数查看增长job的状况
crontab -l若是须要编辑使用-e参数既可。
if [ $STATUS == "OK" ]; then echo "OK" fi
if [[ $STATUS = "OK" ]]; then echo "OK" fi方法二:
if [ "$STATUS"x == "OK"x ]; then