功能:实现工程名/src/main/resources/online和 工程名/src/main/resources/performance下的配置文件的比较(后者比前者缺失哪些配置文件,后者比前者缺失哪些配置项)
代码:
#!/bin/bash # by wuboxiao rm -rf checkConfig.diff checkConfig.error checkConfig.result linenum.txt checkConfig.res files=`find $1/src/main/resources/online -name "*.properties"` #feflag:是否存在配置文件缺失的标志 feflag=0 #fdifftflag:文件存在差异时的首行提示文字“缺失的配置项检查结果:”是否存在的标志 fdifftflag=0 for i in $files;do checkFile=${i/online/"$2"} checkFileName=${checkFile##*/} if [ ! -f $checkFile ];then feflag=1 echo -e " "$checkFileName 1>> checkConfig.error continue fi diff $i $checkFile 1>> checkConfig.result if [ $? -eq 0 ];then #两个文件完全一致 continue elif [ $? -eq 1 ];then #结果为1代表两个配置文件有差异 if [ $fdifftflag -eq 0 ];then echo "缺失的配置项检查结果:" 1>> checkConfig.diff fdifftflag=1 fi fdiflag=0 cat $i | grep -v "^#" | grep -v "^$" | while read line do key=$(echo $line | sed -e ‘s/\(.*\)=\(.*\)/\1/g‘) key_find=$( grep "$key=\(.*\)" $checkFile | sed -e ‘s/\(.*\)=\(.*\)/\1/g‘) if [ -z "$key_find" ];then if [ $fdiflag -eq 0 ];then echo -e $checkFileName 1>>checkConfig.diff fdiflag=1 fi echo -e "\t"$key 1>>checkConfig.diff fi done fi done lostfilenum=$(cat checkConfig.error | wc -l) echo -e "\e[1;31m"$2"缺少"$lostfilenum"个配置文件\e[0m" echo -e " \c" filelines=1 if [ $lostfilenum -ne 0 ];then # echo -e "配置文件:\c" cat checkConfig.error | while read line do if [ $filelines -eq "$lostfilenum" ];then echo -e $line break fi echo -e $line"、\c" ((filelines++)) done fi echo "" chkfilelines=$(cat checkConfig.diff | wc -l) #echo "缺失配置项为"$chkfilelines"个" alllostitem=$(grep -v ‘.properties‘ checkConfig.diff | wc -l) sed -i ‘1s/^.*/‘"$2"‘缺少‘"$((alllostitem-1))"‘个配置项/g‘ checkConfig.diff echo -e "\e[1;31m"$2"缺少"$((alllostitem-1))"个配置项\e[0m" 1>> checkConfig.res if [ $chkfilelines -eq 1 ];then echo " 无配置项缺失" 1>> checkConfig.diff cat checkConfig.diff else linecnt=1 cat checkConfig.diff | awk ‘NR>1‘ | while read line do result=$(echo $line | grep "properties" ) ((linecnt++)) if [ ! "$result"x == ""x ];then echo $linecnt 1>>linenum.txt fi done echo $((chkfilelines+1)) 1>>linenum.txt start=$(cat linenum.txt | awk ‘NR==1‘) cat linenum.txt | awk ‘NR>1‘ | while read end do sed -i "$start"‘s/$/&缺少‘"$((end-start-1))"‘个配置项/g‘ checkConfig.diff awk ‘NR==‘"$start" checkConfig.diff 1>>checkConfig.res linecount=1 echo -e " \c" 1>>checkConfig.res awk ‘NR>‘"$start"‘ && NR<‘"$end" checkConfig.diff | while read eachline do if [ $linecount -lt $((end-start-1)) ];then echo -e $eachline"、\c" 1>>checkConfig.res else echo -e $eachline 1>>checkConfig.res fi ((linecount++)) done start=$end echo "" 1>>checkConfig.res done fi #cat checkConfig.diff cat checkConfig.res rm -rf check.result checkConfig.diff checkConfig.error linenum.txt checkConfig.res
效果:
时间: 2024-10-17 15:23:56