由于测试服务器经常需要更新,觉得太麻烦就写了个shell脚本,记录下来仅供大家参考 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 #!/bin/bash #------自动部署多个tomcat项目脚本------ #1.删除部署目录下已存在的项目 #2.解压war包到对应目录下 #3.重新启动tomcat服务器 #-------------------------------------- home_dir=/home/t0mcat #tomcat目录 soa_tomcat_path=/opt/software/apache-tomcat-7.0.64_SOA #部署目录 soa_deployment_path=/opt/software/web/dev/yiweinet-soa #war包名称 soa_war=business-soa.war mer_tomcat_path=/opt/software/apache-tomcat-7.0.64_MERCHANT mer_deployment_path=/opt/software/web/dev/business-merchant mer_war=business-merchant.war #get war and return path findAllWar(){ cd $home_dir v_war_file_list=$(find -name "*.war") echo "war list:" ls $v_war_file_list } process(){ for i in $(findAllWar) do v_file_path=$i #echo $v_file_path v_file_name=${v_file_path##*/} echo $v_file_name if [ $v_file_name = $soa_war ] then operTomcat $soa_war $soa_deployment_path $soa_tomcat_path fi if [ $v_file_name = $mer_war ] then operTomcat $mer_war $mer_deployment_path $mer_tomcat_path fi done } operTomcat() { stopTomcat $3 #get first param length v_file_length=${#1} #get file name(1 is first param) v_file_name=${1:0:$[ $v_file_length - 4 ]} #del and move war cd $2 rm -rf $v_file_name* jar xvf ${home_dir}/$1 startTomcat $3 } stopTomcat() { cd $1"/bin" ./shutdown.sh #rm -rf $1"/logs/"* echo "$1 shutdown over" } startTomcat() { cd $1"/bin" ./startup.sh echo "$1 start over" } echo "start" process echo "end"