公司有一台服务器起了多个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 |
使用这个脚本启动或者重启完关闭终端前一定要ctrl+c终止日志输出,不然会悲剧的发现tomcat在你直接关闭掉终端以后也挂掉了。
转载于:https://blog.51cto.com/cnlinux/1548451