公司有一台服务器起了多个tomcat,每次需要重启,查看catalina.out输出都特别麻烦,写了一个脚本,贴出来,希望有经验的前辈指点一二,脚本如下:
#!/bin/sh echo "请选择要操作的tomcat实例:" echo "1 : tomcat" echo "2 : tomcat2" echo "3 : tomcat_errorQues" tomcatid=`ps aux | grep java | grep -v grep | grep "/usr/local/tomcat/" |awk ‘{print $2}‘` tomcat2id=`ps aux | grep java | grep "/usr/local/tomcat2/" | grep -v grep | awk ‘{print $2}‘` tomcat_errorQuesid=`ps aux | grep java | grep "/usr/local/tomcat_errorQues/" | grep -v grep | awk ‘{print $2}‘` read name case $name in 1) pid=$tomcatid name=tomcat;; 2) pid=$tomcat2id name=tomcat2;; 3) pid=$tomcat_errorQuesid name=tomcat_errorQues;; *) echo "pleace choose [ 1 | 2 | 3 ]" exit;; esac echo "请输入要执行的操作:[stop | start | restart ]" read operate case $operate in stop) if [ "$(ps aux | grep "java" | grep "$name" | grep -v grep)" == "" ] then echo $name is already stoped! exit 0 else kill -9 $pid && echo tomcat is stoped fi ;; start) if [ "$(ps aux | grep "java" | grep "$name" | grep -v grep)" != "" ] then echo $name is already running! exit 0 else /usr/local/$name/bin/startup.sh && echo "ok" && sleep 2 && tail -200f /usr/local/$name/logs/catalina.out fi ;; restart) if [ "$(ps aux | grep "java" | grep "$name" | grep -v grep)" == "" ] then echo $name is not running,pleace use start frist! exit 0 else kill -9 $pid && /usr/local/$name/bin/startup.sh && echo "ok" && sleep 2 && tail -200f /usr/local/$name/logs/catalina.out fi ;; *) echo "Options error! pleace use [ stop | start | restart ]" ;; esac |
本文出自 “生命不止” 博客,请务必保留此出处http://cnlinux.blog.51cto.com/6112794/1548451
原文地址:http://cnlinux.blog.51cto.com/6112794/1548451