1、需求描述
對于上線步驟較為繁瑣且注意的細節很多的專案,盡可能減少人為現場操作命令,讓機器自動化實作上線功能尤為重要,
2、工具概述
工具啟動后,會提示用戶選擇按系統指引執行(a)或輸入指定指令執行(b)
每一步都會進行簡單的用戶互動(Y/N)后系統自動執行確認后的命令
工具包含的功能有:執行sql檔案、發布應用程式、啟動(重啟)應用程式
3、工具結構
專案名稱
etc/
sh/
help.sh
step.sh
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 工具啟動腳本
4、代碼展示
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
etc/const.lst
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"
etc/dbinfo.cfg
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}
etc/file.cfg
#步驟清單 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
etc/func.cfg
#!/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/step.lst
環境資訊檢查 ./etc/sh/env.sh 應用程式啟動(或重啟) ./etc/sh/app_startup.sh
etc/sh/help.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 ""
etc/sh/top.sh
#!/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 ""
etc/sh/step.sh
#!/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"
etc/sh/wrapper.sh
#!/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
etc/sh/env_db.sh
#!/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}
etc/sh/app_startup.sh
#!/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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/9756.html
標籤:Linux
下一篇:求教vi批量替換問題
