1. 程式人生 > >輸入對應安裝包版本號自動升級指令碼

輸入對應安裝包版本號自動升級指令碼

指令碼大致如下

###made by h###
if [ -z "$readversion" ]; then       
	echo ---------------------------------     
	#顯示目錄下所有agent安裝包
	echo "List file[該目錄下安裝包為]:::"
	ls agent*.tar.gz
	ls AGENT*.tar.gz
	echo ---------------------------------
	#檢視已安裝舊版本
	echo "已安裝版本:::"
	cat /opt/server/web/agent/version.properties
	echo
	echo ---------------------------------
	

		########### 檢查版本號是否為數字串
	 i=1
        while(($i<100))
        do
		
            echo "Input version info [輸入需升級版本號(檔名末尾四位數字)]:::"
	   read vernum
            sleep 1
                ############
                expr $vernum "+" 10 &> /dev/null
                if [ $? -eq 0 ];then
						echo ---------------------------------
                        echo "YOU INPUT VERSION INFO (版本號)::: $vernum"
						echo ---------------------------------
                readversion=$vernum;
		sleep 2

	#輸入正確則解壓對應安裝包安裝,輸入錯誤則exit0
	if [ -e "AGENT-$readversion-V1.tar.gz" ];then
	tar -zxvf AGENT-$readversion-V1.tar.gz
	else
	echo ---------------------------------
	echo -e "\033[31mNo such file or directory[無此安裝包]\033[0m"
	echo ---------------------------------
	exit 0 
	fi	
	sleep 5
	cd agent_$vernum-V1
	sh install.sh
	#顯示程序執行狀態新裝版本號和啟動程序(start.sh中已有kill舊程序號重啟功能)
	cd /opt/server/web/agent
	echo ---------------------------------
	ps -ef|grep agent.jar
	echo ---------------------------------
	./start.sh
	sleep 5
	echo ---------------------------------
	ps -ef|grep agent.jar
	echo ---------------------------------
	echo "版本號:::"
	cat version.dat
	echo
	echo ---------------------------------
	echo -e "\033[32mFinish[已完成升級]\033[0m"
	echo ---------------------------------
	exit 0




                        break
                        #輸入版本號錯誤調至此處
                else
                        echo -e "\033[31mYOU INPUT VERSION INFO [版本號] NOT A number[請輸入數字]!!!\033[0m"
                        let "i++"
                fi
        done
fi