查看进程jc#!/bin/shexportCATALINA_BASE=$(cd`dirname$0`;pwd)。$CATALINA_BASE/setenv.sh$*echo"进程信息:"ps-ef|grep"^$ROOT_USER"|grep$JAVA_HOME|grep$CATALINA_HOME|grep"$CATALINA_BASE"|grep-v'grep'查看日志rz#!/bin/shCATALINA_BASE=$(cd`dirname$0`;pwd)tail-n100-f$CATALINA_BASE/logs/catalina.out设置环境变量setenv.sh#!/bin/shROOT_USER=rootexportJAVA_HOME=/usr/java/jdk1.7.0_80exportCATALINA_HOME=/usr/tomcat/apache-tomcat-8.0.50exportJAVA_OPTS="-server-XX:PermSize=128m-XX:MaxPermSize=256m-Xms512m-Xmx512m-Djava.awt.headless=true"关闭tomcat实例:shutdown.sh#!/bin/shexportCATALINA_BASE=$(cd`dirname$0`;pwd).$CATALINA_BASE/setenv.sh$*WHO=`whoami`GetPid(){PS_ID=$(ps-ef|grep"^$WHO"|grep$JAVA_HOME|grep$CATALINA_HOME|grep"$CATALINA_BASE"|grep-v'grep'|awk'{print$2}')}ShowPid(){echo"进程信息:"ps-ef|grep"^$WHO"|grep$JAVA_HOME|grep$CATALINA_HOME|grep"$CATALINA_BASE"|grep-v'grep'}CountPid(){COUNT=$(ps-ef|grep"^$WHO"|grep$JAVA_HOME|grep$CATALINA_HOME|grep"$CATALINA_BASE"|grep-v'grep'|wc-l)}StopTomcat(){STOP_RESULT=`$CATALINA_HOME/bin/catalina.shstop>/dev/null2>&1|grep"ConnectionRefused"|grep-vgrep|wc-l`}CountPidif[[$COUNT=="0"]];thenecho"服务没有启动。"elseShowPidStopTomcatfor((i=1;i<=30;i++));dofor((j=1;j<=5;j++));dosleep0.5printf"."doneCountPidif[[$COUNT-gt0]];thenStopTomcatelif[[$COUNT-eq0]];然后休息;fidonefor((i=1;i<=120;i++));doif[[$COUNT-gt0]];thensleep0.5printf".."CountPidfidone#如果超时,直接杀死if[[$COUNT-gt0]];thenGetPidkill-9$PS_IDfiif[[$?==0]];thenecho"TOMCAT服务已停止@$CATALINA_BASE"fifi启动tomcat实例:startup.sh#!/bin/shexportCATALINA_BASE=$(cd`dirname$0`;pwd)。$CATALINA_BASE/setenv.sh$*WHO=`whoami`COUNT=$(ps-ef|grep"^$WHO"|grep$JAVA_HOME|grep$CATALINA_HOME|grep"$CATALINA_BASE"|grep-v'grep'|wc-l)回声“************************************************************"echo"当前配置目录:$CATALINA_BASE"echo"*********************************************************”if[[$COUNT-ge1]];thenecho“服务正在运行,请先关机。”else$CATALINA_HOME/bin/catalina.sh开始|awk'{printf"..."}END{print"开始完成"}'如果[[$?==0]];然后echo"TOMCAT启动成功@$CATALINA_BASE"fifiecho"进程信息:"ps-ef|grep"^$WHO"|grep$JAVA_HOME|grep$CATALINA_HOME|grep"$CATALINA_BASE"|grep-v'grep'
