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重启的脚本

本文出自 “一路向北” 博客,请务必保留此出处http://janan.blog.51cto.com/7466674/1569883

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。