標籤:shell測試 tomcat重啟
[[email protected] bin]$ sh -n restart.sh
[[email protected] bin]$
-n:不要執行script,僅僅檢查文法,如果正確不會有任何輸出,如果有錯,則會有提示
[[email protected] bin]$ sh -x restart.sh
+ TOMCAT_HOME=/opt/apache-tomcat-8.0.14
+ cd /opt/apache-tomcat-8.0.14/bin
++ ps -ef
++ grep -v grep
++ wc -l
++ grep /opt/apache-tomcat-8.0.14
+ declare -i count=1
+ ‘[‘ 1 -eq 0 ‘]‘
+ echo ‘shutdown ......‘
shutdown ......
+ ./shutdown.sh
Using CATALINA_BASE: /opt/apache-tomcat-8.0.14
Using CATALINA_HOME: /opt/apache-tomcat-8.0.14
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.14/temp
Using JRE_HOME: /usr/java/jdk1.8.0_25
Using CLASSPATH: /opt/apache-tomcat-8.0.14/bin/bootstrap.jar:/opt/apache-tomcat-8.0.14/bin/tomcat-juli.jar
++ ps -ef
++ grep /opt/apache-tomcat-8.0.14
++ grep -v grep
++ wc -l
+ count=1
+ ‘[‘ 1 -ne 0 ‘]‘
++ ps -ef
++ grep /opt/apache-tomcat-8.0.14
++ grep -v grep
++ awk ‘{print $2}‘
+ declare -i pid=14433
+ kill 14433
+ echo ‘tomcat is down‘
tomcat is down
+ ./startup.sh
Using CATALINA_BASE: /opt/apache-tomcat-8.0.14
Using CATALINA_HOME: /opt/apache-tomcat-8.0.14
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.14/temp
Using JRE_HOME: /usr/java/jdk1.8.0_25
Using CLASSPATH: /opt/apache-tomcat-8.0.14/bin/bootstrap.jar:/opt/apache-tomcat-8.0.14/bin/tomcat-juli.jar
Tomcat started.
+ exit 0
[[email protected] bin]$
-x:執行並輸出script
[[email protected] bin]$ sh -v restart.sh
#!/bin/bash
TOMCAT_HOME=${TOMCAT_HOME:=/opt/apache-tomcat-8.0.14}
cd $TOMCAT_HOME/bin
declare -i count=`ps -ef|grep $TOMCAT_HOME|grep -v "grep"|wc -l`
ps -ef|grep $TOMCAT_HOME|grep -v "grep"|wc -l
if [ $count -eq 0 ];then
echo "tomcat is not started"
else
echo "shutdown ......"
./shutdown.sh
count=`ps -ef|grep $TOMCAT_HOME|grep -v "grep"|wc -l`
if [ $count -ne 0 ];then
declare -i pid=`ps -ef|grep $TOMCAT_HOME|grep -v "grep"|awk ‘{print $2}‘`
kill $pid
fi
echo "tomcat is down"
fi
./startup.sh
shutdown ......
Using CATALINA_BASE: /opt/apache-tomcat-8.0.14
Using CATALINA_HOME: /opt/apache-tomcat-8.0.14
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.14/temp
Using JRE_HOME: /usr/java/jdk1.8.0_25
Using CLASSPATH: /opt/apache-tomcat-8.0.14/bin/bootstrap.jar:/opt/apache-tomcat-8.0.14/bin/tomcat-juli.jar
ps -ef|grep $TOMCAT_HOME|grep -v "grep"|wc -l
ps -ef|grep $TOMCAT_HOME|grep -v "grep"|awk ‘{print $2}‘
tomcat is down
Using CATALINA_BASE: /opt/apache-tomcat-8.0.14
Using CATALINA_HOME: /opt/apache-tomcat-8.0.14
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.14/temp
Using JRE_HOME: /usr/java/jdk1.8.0_25
Using CLASSPATH: /opt/apache-tomcat-8.0.14/bin/bootstrap.jar:/opt/apache-tomcat-8.0.14/bin/tomcat-juli.jar
Tomcat started.
exit 0
[[email protected] bin]$
-v:先輸出,後執行,紅色部分就是指令碼,這個是tomcat重啟的指令碼
本文出自 “一路向北” 部落格,請務必保留此出處http://janan.blog.51cto.com/7466674/1569883
shell script的追蹤