shell script的追蹤

來源:互聯網
上載者:User

標籤: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的追蹤

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.