Here is a script example to replace log4j in bulk.
How to Replace log4j with shell Script in Bulk
#!/bin/ bash # #java 6 log4j file directory lpath6 =/opt/test/ repl6 #java 7 log4j file directory lpath7 =/opt/test/ repl7 jarname = ' log4j*.jar ' #status value stat = 0 #The production environment can modify the following line to $(ps -ef |grep java |grep -v grep) |while read pro Extract the current java process. 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