shell script的追蹤

[zengchao@localhost bin]$ sh -n restart.sh 

[zengchao@localhost bin]$ 

-n:不要執行script,僅僅檢查語法,如果正確不會有任何輸出,如果有錯,則會有提示


[zengchao@localhost 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

[zengchao@localhost bin]$ 

-x:執行並輸出script


[zengchao@localhost 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

[zengchao@localhost bin]$ 

-v:先輸出,後執行,紅色部分就是腳本,這個是tomcat重啓的腳本

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章