[Email protected] bin]$ sh-n restart.sh
[Email protected] bin]$
-N: Do not execute script, just check the syntax, if there is no output correctly, if there is an error, you will be prompted
[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 $} '
+ 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: Execute and Output 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 $} '
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 $} '
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: Output First, then execute, the red part is the script, this is the Tomcat restart script
This article is from the "All the Way North" blog, please be sure to keep this source http://janan.blog.51cto.com/7466674/1569883
Shell Script Tracking