关闭所有tomcat
#!/bin/sh #kill tomcat pid pidlist=`ps -ef|grep tomcat | grep -v "grep"|awk '{print $2}'` #ps -u $USER|grep "java"|grep -v "grep" echo "tomcat Id list :$pidlist" if [ "$pidlist" = "" ] then echo "no tomcat pid alive" else for pid in ${pidlist} { kill -9 $pid echo "KILL : $pid" echo "service stop success" } fi
重启指定的tomcat
#!/bin/sh
tomcat_home=/home/tomcat7_monitor STARTTOMCAT=$tomcat_home/bin/startup.sh
echo "关闭$tomcat_home" #kill tomcat pid pidlist=`ps -ef|grep $tomcat_home | grep -v "grep"|awk '{print $2}'` echo "tomcat Id list :$pidlist" if [ "$pidlist" = "" ] then echo "no tomcat pid alive" else for pid in ${pidlist} { kill -9 $pid echo "KILL $pid:" echo "service stop success" } fi #delete logs rm $tomcat_home/logs/* -rf #delete work rm $tomcat_home/work/* -rf sleep 5 echo "启动$tomcat_home" $STARTTOMCAT #看启动日志 tail -f $tomcat_home/logs/catalina.out