相信不少用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