對於上線步驟較爲繁瑣且注意的細節不少的項目,儘量減小人爲現場操做命令,讓機器自動化實現上線功能尤其重要。web
工具啓動後,會提示用戶選擇按系統指引執行(a)或輸入指定指令執行(b)sql
每一步都會進行簡單的用戶交互(Y/N)後系統自動執行確認後的命令shell
工具包含的功能有:執行sql文件、發佈應用程序、啓動(重啓)應用程序數據庫
項目名稱app
etc/函數
sh/工具
help.shui
step.shspa
top.sh日誌
wrapper.sh
const.lst
dbinfo.cfg
file.cfg
func.cfg
step.lst
step_run.log
log/
source/
tool/
execSqlFile.sh
run.sh
目錄或文件說明:
etc/ 配置文件存放目錄
etc/sh 可執行的shell腳本,如help.sh,輸出工具幫助信息;step.sh,輸出項目部署步驟信息;top.sh,輸出項目部署標題;wrapper.sh,自定義shell腳本的包裝類,可實現shell腳本執行先後動做,如日誌打印
etc/const.lst 工具常量文件
etc/dbinfo.cfg 數據庫鏈接信息
etc/file.cfg 全部文件或目錄常量文件
etc/func.cfg 公共函數
step.lst 項目部署步驟清單
step_run.log 步驟執行日誌,日誌內容包含步驟名稱、執行狀態(0成功 1失敗)、開始時間、結束時間、耗時(秒)
log/ 日誌目錄
source/ 數據文件存放目錄
tool/ 工具腳本存放目錄,如execSqlFile.sh,傳入可執行sql文件路徑參數,用於 執行sql文件
run.sh 工具啓動腳本
#!/bin/sh cd `dirname $0` #加載靜態資源 . ./etc/const.lst . ./etc/dbinfo.cfg . ./etc/file.cfg . ./etc/func.cfg function init { clear #打印標題 ./etc/sh/top.sh checkstatus $? "輸出標題" #打印操做步驟 ./etc/sh/step.sh checkstatus $? "輸出操做步驟" } init if [ ! -f ${hkbaps_step_log} ]; then touch ${hkbaps_step_log} fi #加載操做步驟 declare -a array declare -a code declare -a cmd cnt=0 while read line do if [[ -n `echo ${line}|grep -v "^\s*$"` ]] && [[ "${line:0:1}" != "#" ]]; then let cnt=cnt+1 code[$cnt]="`lpad ${cnt} 3`" array[$cnt]="${code[$cnt]}-`echo ${line}|awk '{print $1}'`" cmd[$cnt]="`echo ${line}|awk '{print $2}'`" fi done < ${hkbaps_step} valid=0 match="" flag=1 index=1 #用戶指令交互 while true do read -r -p "您是否選擇按照操做步驟清單指引執行(a)或手工輸入指定任務代碼指令執行(b)? " inp case $inp in [aA]) while true do if [ ${valid} -eq 0 ]; then #判斷最近是否存在未完成的任務 slog=`cat ${hkbaps_step_log}|grep -v "^\s*$"|tail -n 1` if [ -n "${slog}" ]; then step=`echo ${slog}|awk '{print $1}'` status=`echo ${slog}|awk '{print $2}'` if [ "${status}" == "1" ]; then match=${step} for((i=1;i<${#array[*]};i++)); do if [ "${array[$i]}" == "${step}" ]; then index=$i flag=0 break fi done if [ ${flag} -eq 1 ]; then match=${step} fi else flag=0 fi else flag=0 fi fi if [ ${flag} -eq 1 ]; then read -r -p "檢測到未完成的任務:${match}不存在當前的操做步驟清單中,請輸入指定任務代碼指令或從新執行全部指令? " input case $input in [nN][oO]|[nN]) output "已取消操做" exit 1 ;; [uU][nN][dD][oO]|[uU]) read -r -p "肯定要從新執行全部任務? [Y/N] " input2 case $input2 in [yY][eE][sS]|[yY]) match="" flag=0 index=1 valid=1 echo "" > ${hkbaps_step_log} ;; [nN][oO]|[nN]) output "已取消操做" valid=1 ;; [cC][lL][eE][aA][rR]|[cC]) init valid=1 ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac ;; [sS][tT][eE][pP]|[sS]) ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) ./etc/sh/help.sh ;; *) exists=0 for((i=1;i<${#code[*]};i++)); do tmp=`upper ${input}` if [ "${tmp}" == "${code[${i}]}" ]; then index=${i} exists=1 break fi done if [ ${exists} -eq 1 ]; then ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]} valid=0 match="" flag=0 let index=index+1 else valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" fi ;; esac else if [[ -n ${match} ]] && [[ ${index} -gt 1 ]]; then read -r -p "檢測到未完成的任務:${match},是否直接執行? [Y/N] " input case $input in [yY][eE][sS]|[yY]) ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]} valid=0 let index=index+1 match="" ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; [uU][nN][dD][oO]|[uU]) read -r -p "肯定要從新執行全部任務? [Y/N] " input2 case $input2 in [yY][eE][sS]|[yY]) match="" flag=0 index=1 valid=1 echo "" > ${hkbaps_step_log} ;; [nN][oO]|[nN]) valid=1 output "已取消操做" ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac ;; [sS][tT][eE][pP]|[sS]) valid=1 ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) valid=1 ./etc/sh/help.sh ;; [cC][lL][eE][aA][rR]|[cC]) valid=1 init ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac else while [ ${index} -lt ${#array[*]} ]; do msg=${array[${index}]} slog=`cat ${hkbaps_step_log}|grep ${msg}|grep -v "^\s*$"|tail -n 1` if [ -n "${slog}" ]; then status=`echo ${slog}|awk '{print $2}'` if [ "${status}" == "0" ]; then read -r -p "步驟:${msg}已成功執行過,確認是否能夠跳過該步驟? [Y/N] " input case $input in [yY][eE][sS]|[yY]) let index=index+1 ;; [nN][oO]|[nN]) break ;; [uU][nN][dD][oO]|[uU]) read -r -p "肯定要從新執行全部任務? [Y/N] " input2 case $input2 in [yY][eE][sS]|[yY]) match="" flag=0 index=1 valid=1 echo "" > ${hkbaps_step_log} ;; [nN][oO]|[nN]) output "已取消操做" valid=1 ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac ;; [sS][tT][eE][pP]|[sS]) valid=1 ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) valid=1 ./etc/sh/help.sh ;; [cC][lL][eE][aA][rR]|[cC]) valid=1 init ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac fi else break fi done let t=index-1 if [[ ${t} -gt 0 ]] && [[ ${index} -lt ${#array[*]} ]]; then msg=${array[${t}]} read -r -p "步驟:${msg}已執行完畢,確認是否能夠執行下一步驟:${array[${index}]}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; [uU][nN][dD][oO]|[uU]) read -r -p "肯定要從新執行全部任務? [Y/N] " input2 case $input2 in [yY][eE][sS]|[yY]) match="" flag=0 index=1 valid=1 echo "" > ${hkbaps_step_log} ;; [nN][oO]|[nN]) output "已取消操做" valid=1 ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac ;; [sS][tT][eE][pP]|[sS]) valid=1 ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) valid=1 ./etc/sh/help.sh ;; [cC][lL][eE][aA][rR]|[cC]) valid=1 init ;; *) valid=1 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac fi if [ ${index} -lt ${#array[*]} ]; then if [ ${index} -eq 1 ]; then msg=${array[${t}]} read -r -p "步驟:${array[${index}]},確認是否開始執行? [Y/N] " input case $input in [yY][eE][sS]|[yY]) ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; [sS][tT][eE][pP]|[sS]) valid=2 ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) valid=2 ./etc/sh/help.sh ;; [cC][lL][eE][aA][rR]|[cC]) valid=2 init ;; *) valid=2 echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac fi if [ ${valid} -ne 2 ]; then ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]} valid=0 let index=index+1 match="" fi else output "任務執行完畢!" exit 1 fi fi fi done ;; [bB]) while true do read -r -p "請輸入步驟指令代碼: " input case $input in [nN][oO]|[nN]) output "已取消操做" exit 1 ;; [sS][tT][eE][pP]|[sS]) ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) ./etc/sh/help.sh ;; [cC][lL][eE][aA][rR]|[cC]) init ;; *) exists=0 for((i=1;i<${#code[*]};i++)); do tmp=`upper ${input}` if [ "${tmp}" == "${code[${i}]}" ]; then index=${i} exists=1 break fi done if [ ${exists} -eq 1 ]; then ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]} else echo -e "不合法的輸入指令${input},請從新輸入!" fi ;; esac done ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; [sS][tT][eE][pP]|[sS]) ./etc/sh/step.sh ;; [hH][eE][lL][pP]|[hH]) ./etc/sh/help.sh ;; [cC][lL][eE][aA][rR]|[cC]) init ;; *) echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac done
sys_name=XXX系統 sys_code=XXX sys_task=上線操做 sys_author=XXX sys_user=XXX sys_skin=[44\;37 LANG="zh_CN.GBK" NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
db_dump_username=XXX db_dump_uo_username=XXX db_username=XXX db_password=XXX db_instance=XXX db_link=${db_username}/${db_password}@${db_instance}
#步驟清單 step=etc/step.lst #步驟執行日誌 step_log=etc/step_run.log #步驟執行包裝器 step_wrapper=./etc/sh/wrapper.sh #數據庫信息檢查語句 db_check_sql=source/env_db.sql #數據庫信息檢查腳本 db_check=./etc/sh/env_db.sh #校驗01 check_01=source/check_01.sql #校驗02 check_02=source/check_02.sql #校驗03 check_03=source/check_03.sql
#!/bin/sh #日誌文件 export logfile=log/`date +%Y%m%d`.log #info級別控制檯日誌 function output { msg=$1 skin=$2 if [ -f "${msg}" ]; then echo `date` >> ${logfile} cat ${msg} >> ${logfile} cat ${msg} else if [ -n "${skin}" ]; then echo -e "\033${skin}${msg}\033[0m" else echo -e ${msg} fi echo -e "`date` ${msg}" >> ${logfile} fi } function title { msg=$1 skin=$2 if [ -n "${skin}" ]; then echo -e "\n\033${skin}\;1m${msg}\033[0m\n" else echo -e "\n\033[1m${msg}\033[0m\n" fi echo -e "`date` \n${msg}\n" >> ${logfile} } function success { msg=$1 if [ ! -n "${msg}" ]; then msg=執行成功 fi output ${msg} } function error { msg=$1 if [ ! -n "${msg}" ]; then msg=執行失敗 fi output ${msg} exit 1 } function checkstatus { code=$1 msg=$2 if [ ${code} -ne 0 ]; then output ${msg}異常:${code} exit 1 fi } function printchar { n=$1 c=$2 s="" if [ ! -n "${n}" ]; then n=20 fi if [ ! -n "${c}" ]; then c="_" fi for((i=1;i<=${n};i++)); do s="${s}${c}" done echo -e ${s} } function seperate { echo "" echo `printchar "-" 300` echo "" } function lpad { char=$1 len=$2 fill=$3 if [ -n "${char}" ]; then if [ ! -n "${len}" ]; then len=8 fi if [ ! -n "${fill}" ]; then fill="0" fi size=${#char} let m=len-size s="" for((i=1;i<=${m};i++)); do s="${s}${fill}" done echo ${s}${char} fi } function lower { msg=$1 if [ -n "${msg}" ]; then if [ -f "${msg}" ]; then cat ${msg}|tr A-Z a-z else echo ${msg}|tr A-Z a-z fi fi } function upper { msg=$1 if [ -n "${msg}" ]; then if [ -f "${msg}" ]; then cat ${msg}|tr a-z A-Z else echo ${msg}|tr a-z A-Z fi fi } #日誌文件錯誤信息檢查 function checklog { reg=$1 log=$2 msg="" if [ ! -f "${log}" ]; then log=${logfile} msg=`cat ${log}|grep -i ${reg}` else msg=`cat ${logfile}|grep -i ${reg}` fi if [ ${#msg} -gt 0 ]; then echo "日誌文件${log},發現報錯信息:${msg}" exit 1 fi } function execSqlFile { dbconn=$1 dbfile=$2 err=$3 if [ ! -n "${dbconn}" ]; then error "數據庫鏈接信息缺失,請檢查" fi if [ ! -f "${dbfile}" ]; then error "sql文件${dbfile}不存在,請檢查" fi if [ ! -n "${err}" ]; then err=ORA- fi read -r -p "即將在數據庫環境${dbconn}中執行sql文件${dbfile}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) sqlplus -S /nolog<<EOF conn ${dbconn} spool ${logfile} append @${dbfile} spool off quit EOF checklog ${err} ;; [nN][oO]|[nN]) echo "已取消操做" ;; *) echo "Invalid input..." exit 1 ;; esac } function execDSqlFile { dbconn=$1 dbfile=$2 err=$3 if [ ! -n "${dbconn}" ]; then error "數據庫鏈接信息缺失,請檢查" fi if [ ! -f "${dbfile}" ]; then error "sql文件${dbfile}不存在,請檢查" fi if [ ! -n "${err}" ]; then err=ORA- fi sqlplus -S /nolog<<EOF conn ${dbconn} spool ${logfile} append @${dbfile} spool off quit EOF } function executeSql(){ dbconn=$1 sql=$2 err=$3 if [ ! -n "${dbconn}" ]; then error "數據庫鏈接信息缺失,請檢查" fi if [ ! -n "${sql}" ]; then error "sql腳本${sql}缺失,請檢查" fi if [ -f "${sql}" ]; then sql=`cat ${sql}` fi lst=${sql: -1} if [ "${lst}" != ";" ]; then sql="${sql};" fi if [ ! -n "${err}" ]; then err=ORA- fi read -r -p "即將在數據庫環境${dbconn}中執行sql語句:${sql}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) sqlplus -S /nolog<<EOF conn ${dbconn} spool ${logfile} append ${sql} spool off quit EOF checklog ${err} ;; [nN][oO]|[nN]) echo "已取消操做" ;; *) echo "Invalid input..." exit 1 ;; esac } function querySingle(){ dbconn=$1 sql=$2 err=$3 if [ ! -n "${dbconn}" ]; then error "數據庫鏈接信息缺失,請檢查" fi if [ ! -n "${sql}" ]; then error "sql腳本${sql}缺失,請檢查" fi if [ -f "${sql}" ]; then sql=`cat ${sql}` fi lst=${sql: -1} if [ "${lst}" != ";" ]; then sql=${sql}; fi if [ ! -n "${err}" ]; then err=ORA- fi read -r -p "即將在數據庫環境${dbconn}中執行sql語句:${sql}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) result=`sqlplus -S /nolog<<EOF set heading off feedback off pagesize 0 verify off echo off conn ${dbconn} spool ${logfile} append ${sql} spool off quit EOF` checklog ${err} echo ${result} ;; [nN][oO]|[nN]) echo "已取消操做" ;; *) echo "Invalid input..." exit 1 ;; esac } function impDump(){ dbconn=$1 file=$2 fromuser=$3 touser=$4 err=$5 if [ ! -n "${dbconn}" ]; then error "數據庫鏈接信息缺失,請檢查" fi if [ ! -f "${file}" ]; then error "導入的dump文件${file}缺失,請檢查" fi if [ ! -n "${fromuser}" ]; then error "導入時數據庫來源用戶缺失,請檢查" fi if [ ! -n "${touser}" ]; then error "導入時數據庫目標用戶缺失,請檢查" fi if [ ! -n "${err}" ]; then err=ORA- fi read -r -p "即將在數據庫環境${dbconn}中執行dump導入,導入文件:${file},來源用戶:${fromuser},目標用戶:${touser}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) tmp="${logfile}.imp.`date +%H%M%S`" imp ${dbconn} file=${file} log=${tmp} STATISTICS=NONE data_only=y fromuser=${fromuser} touser=${touser} checklog ${err} ${tmp} ;; [nN][oO]|[nN]) echo "已取消操做" ;; *) echo "Invalid input..." exit 1 ;; esac } function exportDump(){ dbconn=$1 file=$2 lst=$3 err=$4 if [ ! -n "${dbconn}" ]; then error "數據庫鏈接信息缺失,請檢查" fi if [ ! -n "${file}" ]; then error "導出dump文件名缺失,請檢查" fi if [ ! -f "${lst}" ]; then error "導出的表清單文件${lst}不存在,請檢查" fi if [ ! -n "${err}" ]; then err=ORA- fi read -r -p "即將在數據庫環境${dbconn}中執行dump導出,導出文件:${file},導出表清單:`cat ${lst}`? [Y/N] " input case $input in [yY][eE][sS]|[yY]) tabs="" while read line do tabs="${tabs},`echo ${line}|awk '{print $1}'`" done < ${lst} if [ -n "${tabs}" ]; then tabs=${tabs:1} tmp="${logfile}.exp.`date +%H%M%S`" exp ${dbconn} file=${file} log=${tmp} tables=${tabs} checklog ${err} ${tmp} fi ;; [nN][oO]|[nN]) echo "已取消操做" ;; *) echo "Invalid input..." exit 1 ;; esac }
環境信息檢查 ./etc/sh/env.sh 應用程序啓動(或重啓) ./etc/sh/app_startup.sh
#!/bin/sh #幫助指南 cd `dirname $0` cd ../../ . ./etc/const.lst . ./etc/file.cfg . ./etc/func.cfg output 幫助指南 "${sys_skin};1m" output "" output "a:按照操做步驟指引執行" output "b:選擇手工輸入指令執行" output "c:清空控制檯" output "h:查看幫助指南" output "n:取消當前操做" output "s:查看操做步驟" output "u:從新執行(注:適合選擇操做指引的方式)" output "y:確認當前系統提示" output ""
#!/bin/sh #輸出控制檯頂部信息 cd `dirname $0` cd ../../ . ./etc/const.lst . ./etc/file.cfg . ./etc/func.cfg header=`printchar 30` header="${header}${sys_name}(${sys_code}) - ${sys_task}${header}" echo -e "\033${sys_skin};1m ${header}\033[0m\033${sys_skin};4m 操做人:${sys_author}\033[0m" echo ""
#!/bin/sh #輸出執行步驟信息 cd `dirname $0` cd ../../ . ./etc/const.lst . ./etc/file.cfg . ./etc/func.cfg output 執行步驟 "${sys_skin};1m" cnt=0 while read line do if [ -n "${line}" ] && [[ "${line:0:1}" != "#" ]]; then let cnt=cnt+1 output ${cnt}、`lpad ${cnt} 3`-`echo ${line}|awk '{print $1}'` fi done < ${hkbaps_step} output "\n"
#!/bin/sh #步驟執行包裝器 cd `dirname $0` cd ../../ . ./etc/const.lst . ./etc/file.cfg . ./etc/func.cfg step=$1 cmd=$2 if [ ! -n ${step} ]; then error "包裝器中執行步驟不能爲空,請檢查!" elif [ ! -n ${cmd} ]; then error "執行步驟:${step}未配置對應執行腳本,請檢查" else output "" output ${step} "${sys_skin};1m" output "" bdate=`date +%Y%m%d%H%M%S` sh ${cmd} tmp=$? output "" edate=`date +%Y%m%d%H%M%S` cost=$(( edate-bdate )) result="" if [[ ${tmp} -ne 0 ]] || [[ ${msg} -ne 0 ]]; then result="${step}\t1\t${bdate}\t${edate}\t${cost}(秒)" else result="${step}\t0\t${bdate}\t${edate}\t${cost}(秒)" fi echo -e ${result} >> ${hkbaps_step_log} fi
#!/bin/sh #數據庫信息檢查 cd `dirname $0` cd ../../ . ./etc/const.lst . ./etc/dbinfo.cfg . ./etc/file.cfg . ./etc/func.cfg execDSqlFile ${db_link} ${hkbaps_db_check_sql}
#!/bin/sh #應用程序啓動(或重啓) cd `dirname $0` cd ../../ . ./etc/const.lst . ./etc/file.cfg . ./etc/func.cfg export LANG=en_US.UTF-8 echo "LANG:$LANG" u=`whoami` if [ "${u}" != "${sys_user}" ]; then output "當前登陸用戶${u}與要求的用戶${sys_user}不符" read -r -p "當前登陸用戶${u}與要求的用戶${sys_user}不符,確認是否用該用戶啓動(重啓)應用? [Y/N] " input case $input in [yY][eE][sS]|[yY]) ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; *) echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac fi #停服務 #中止web應用服務 web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep` if [ -n "${web_log}" ]; then sh ${app_web}/bin/shutdown.sh fi cnt=0 while [ ${cnt} -lt 3 ] do web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep` if [ -n "${web_log}" ]; then let cnt=cnt+1 sleep 2 else break fi done web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep` if [ -n "${web_log}" ]; then output ${web_log} progress=`echo ${web_log}|awk '{print $2}'` read -r -p "web應用中止服務耗時過久,是否強制中止進程-${progress}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) kill -9 ${progress} ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; *) echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac fi #中止server應用服務 server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep` if [ -n "${server_log}" ]; then sh ${app_server}/bin/shutdown.sh fi cnt=0 while [ ${cnt} -lt 3 ] do server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep` if [ -n "${server_log}" ]; then let cnt=cnt+1 sleep 2 else break fi done server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep` if [ -n "${server_log}" ]; then output ${server_log} progress=`echo ${server_log}|awk '{print $2}'` read -r -p "server應用中止服務耗時過久,是否強制中止進程-${progress}? [Y/N] " input case $input in [yY][eE][sS]|[yY]) kill -9 ${progress} ;; [nN][oO]|[nN]) output "已取消操做" exit 1 ;; *) echo -e "不合法的輸入指令${input},請從新輸入!" ;; esac fi #啓服務 sh ${app_server}/bin/startup.sh && sh ${app_web}/bin/startup.sh cnt=0 while [ ${cnt} -lt 3 ] do server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep` if [ -n "${server_log}" ]; then progress=`echo ${server_log}|awk '{print $2}'` output "server應用服務啓動成功,進程號:${progress}" break else let cnt=cnt+1 sleep 2 fi done cnt=0 while [ ${cnt} -lt 3 ] do web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep` if [ -n "${web_log}" ]; then progress=`echo ${web_log}|awk '{print $2}'` output "web應用服務啓動成功,進程號:${progress}" break else let cnt=cnt+1 sleep 2 fi done