shell批量log4j版本替换

    在实际的应用中,有很多工程,手动单个替换很麻烦,写了如下脚本。

 

#!/bin/bash
#

#java 6 log4j文件目录
lpath6=/opt/test/repl6
#java 7 log4j文件目录 lpath7
=/opt/test/repl7
jarname
='log4j*.jar' #状态值 stat=0 #生产环境可将下行修改为 $(ps -ef |grep java |grep -v grep) |while read pro 提取当前java进程。 cat grepfile.txt |while read pro do propath=$(echo ${pro} |awk -F" " '{print $9}' |awk -F"=" '{print $2}' |awk -F "tomcat" '{print $1}') if [ -d ${propath} ];then echo "----update path: ${propath} starting------" echo ${pro} |awk -F" " '{print $8}' |grep 1.6 if [ $? -eq 0 ];then echo "-----jdk 1.6-------" for file in $(find ${propath} -name ${jarname} -print) do echo ${file} mv -f ${file} ${file}_$(date +%y%m%d%H%M%S) && echo "${file} back complete!" done \cp ${lpath6}/* ${propath} && echo "cp ${lpath6}/* /${propath} complete" stat=1 else echo "-----Discontent-----" fi if [ ${stat} -eq 0 ];then echo ${pro} |awk -F" " '{print $8}' |grep 1.7 if [ $? -eq 0 ];then echo "-----jdk 1.7-------" for file in $(find ${propath} -name ${jarname} -print) do echo ${file} mv -f ${file} ${file}_$(date +%y%m%d%H%M%S) && echo "${file} back complete!" done \cp ${lpath7}/* ${propath} && echo "cp ${lpath7}/* /${propath} complete" else echo "-----Discontent-----" fi else stat=0 fi else echo "----update path: ${propath} no exist------" fi done

 

posted on 2022-02-25 10:04  浊酒三杯  阅读(116)  评论(0编辑  收藏  举报