#!/bin/sh#定义tomcat路径变量:完整路径或最后级路径文件夹都可以tomcat_path='/usr/dev/tomcat' #获取 tomcat_path 所知tomcat 的进程IDTomcatID=$(ps -ef |grep tomcat |grep -w $tomcat_path|grep -v 'grep'|awk '{print $2}')echo "##############################################开始重启Tomcat Server[$tomcat_path、进程ID:$TomcatID]################################################"#判断进程是否存在 注意空格,if用法参照http://blog.chinaunix.net/uid-20735106-id-3434959.htmlif [ "$TomcatID" != "" ] ; then echo "Tomcat Server[$tomcat_path、进程ID:$TomcatID] Was Started! Begin To Shutdown Tomcat Server!" sh /usr/dev/tomcat/bin/shutdown.sh echo "Tomcat Server[$tomcat_path] Was Shutdown! Begin To Restart Tomcat Server!" sh /usr/dev/tomcat/bin/startup.sh echo "Tomcat Server[$tomcat_path] Was Started!"else echo "Tomcat Server[$tomcat_path] Has Not Started! Begin to Start Tomcat Server!" sh /usr/dev/tomcat/bin/startup.sh echo "Tomcat Server[$tomcat_path] Was Started!"fiNewTomcatID=$(ps -ef |grep tomcat |grep -w $tomcat_path|grep -v 'grep'|awk '{print $2}')if [ "$NewTomcatID" != "" ] ; then echo "#############################################Success:Tomcat Server[$tomcat_path、进程ID:$NewTomcatID]重启完毕!#############################################"else echo "################################################Fail:Tomcat Server[$tomcat_path]重启失败!############################################"fi