当前位置: > shell编程 >

linux shell 编程7 tomcat的启动停止

时间:2016-06-12 23:36来源:linux.it.net.cn 作者:IT
 
  1. #!/bin/bash  
  2. JAVA_HOME="/usr/local/jdk1.7/jdk1.7"  
  3. TOMCAT_HOME="/usr/local/tomcat/apache_tomat-8"  
  4. export JAVA_HOME  
  5. usage="{stop|start|restart}"  
  6. start_tomcat="$TOMCAT_HOME/bin/startup.sh"  
  7. stop_tomcat="$TOMCAT_HOME/bin/shutdown.sh"  
  8. # look  pid  isexists   
  9. # THIS IS GET  PID   
  10. PID=$( netstat -anp | grep 8080 |awk '{print $7}' | awk '{split($0,b,"/");print b[1]}')  
  11. # THIS IS REGULAR GET  NUMBER  
  12. RES=$(echo "$PID" |awk '{if($0 ~ /^[0-9]+$/) print $0;}')  
  13. echo " value of tomcat pid------------------------> $PID"  
  14. echo "value of  pid res---------------------------> $RES"  
  15. start(){  
  16. echo "starting  tomcat..."  
  17. if [ -z "$RES" ]  
  18. then  
  19. ${start_tomcat}  
  20. echo "start tomcat ok !"  
  21. else  
  22. echo "start tomcat ok ^^ !"  
  23. fi  
  24. }  
  25. stop(){  
  26. echo "stoping  tomcat..."  
  27. if [ -n "$RES" ]  
  28. then  
  29. ${stop_tomcat}  
  30. echo "stoped tomcat ok!"  
  31. else  
  32. echo "stoped tomcat ok ^^ !"  
  33. fi  
  34. }  
  35.   
  36. #  read arg   
  37. echo " please input: $usage "  
  38. read ANS  
  39. case $ANS in  
  40. start)  
  41. start  
  42. ;;  
  43. stop)  
  44. stop  
  45. ;;  
  46. restart)  
  47. stop  
  48. start  
  49. ;;  
  50. *)  
  51. echo " please input :$usage"  
  52. exit 1  
  53. ;;  
  54. esac  




(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容