Shell指令碼對tomcat進行操作
阿新 • • 發佈:2018-12-13
首先使用 vi tomcat.sh新建檔案
然後i鍵進入編輯,下面是shell指令碼程式碼
tomcatPath=/hw/tomcat/apache-tomcat-8.5.20 if [ "$1" == "help" ];then echo "[ ==這是幫助資訊== ]" echo " ---> 1.使用help引數顯示幫助資訊" echo " ---> 2.使用kill可以停止tomcat" echo " ---> 3.使用start啟動tomcat" echo " ---> 4.使用預設配置重啟tomcat" echo " ---> 5.使用log顯示日誌" echo " ---> 6.使用port顯示埠" exit 0; fi echo " --->" echo " ---> tomcat目錄的位置為$tomcatPath" #echo " ---> 設定命令 dspt_dir為跳轉到tomcat目錄" echo " --->" #echo "alias dspt_dir='cd $tomcatPath'" > .bashrc port=$(ps -ef | grep $tomcatPath | awk '{print $2}') echo " ---> Tomcat run at port:$port" if [ $1 == "kill" ];then echo " ---> 正在kill tomcat程序!" kill -9 $port exit 0 fi if [ $1 == "start" ];then echo " ---> 正常啟動tomcat服務" $tomcatPath"/bin/startup.sh" exit 0 fi if [ $1 == "log" ];then tail -f $tomcatPath"/logs/catalina.out" exit 0; fi if [ $1 == "port" ];then echo " ---> 該tomcat所有的埠列表" ps -ef | grep $tomcatPath | awk '{print $2}' exit 0; fi read -t 10 -p " ---> 請輸是否確定重啟tomcat(Y/N):" restart if [ $restart"O" == "YO" ];then echo " ---> 正在重啟Tomcat" kill -9 $port $tomcatPath/bin/startup.sh & tail -f $tomcatPath"/logs/catalina.out" exit 0 fi