#!/bin/bash
BSU_PACH=/home/weblogic/Oracle/Middleware/utils/bsu
WLSHOME_PACH=/home/weblogic/Oracle/Middleware/wlserver_10.3
PKG_PACH=ftp://10.1.1.1/patch/weblogic/10.3.6/
PKG_NAME=p33172858_1036_Generic.zip

# 判断清空旧文件夹中内容或创建补丁文件夹
if [ -d ${BSU_PACH}/cache_dir ];then
cd ${BSU_PACH}/cache_dir; rm -rf *
else
mkdir -p ${BSU_PACH}/cache_dir
fi

# PKG_NAME是补丁包名称
cd ${BSU_PACH}/cache_dir && curl -o ./${PKG_NAME} ${PKG_PACH}/${PKG_NAME}

# 解压补丁包
cd ${BSU_PACH}/cache_dir && unzip *.zip

#更改bsu.sh脚本中的内存参数,提高打补丁速度
if [ -f ${BSU_PACH}/bsu.sh.bak ];then
echo “bsu has changed.”
else
cp ${BSU_PACH}/bsu.sh ${BSU_PACH}/bsu.sh.bak
cd ${BSU_PACH} && sed -i ‘5c MEM_ARGS=”-Xms4096m -Xmx4096m -XX:-UseGCOverheadLimit”‘ ./bsu.sh
fi

#停服务
ps -ef | grep java| grep weblogic | grep -v “grep” 2>&1 >/dev/null
if [[ $? -eq 0 ]];then
ps -ef |grep java| grep weblogic | grep -v “grep”|awk ‘{print $2}’|xargs kill -9
else
echo “weblogic process is not exsits”
fi

#打补丁:
cd ${WLSHOME_PACH}/server/bin && source setWLSEnv.sh
cd ${BSU_PACH}/cache_dir && PK=$(ls -lt *.jar | head -n 1 | awk ‘{print $NF}’ | awk -F “.” ‘{print $1}’)
cd ${BSU_PACH} && ./bsu.sh -install -patch_download_dir=${BSU_PACH}/cache_dir -patchlist=${PK} -prod_dir=${WLSHOME_PACH}

#启动weblogic服务
#nohup /home/weblogic/Oracle/Middleware/user_projects/domains/base_domain/bin/startWebLogic.sh &