Mother of an egg, wrote a fried chicken trash script, also drunk

Source: Internet
Author: User

Features: Implements a comparison of the configuration files under the project name/src/main/resources/online and the project name/src/main/resources/performance (which configuration files are missing from the former, which are the ones that are missing from the former)

Code:

#!/bin/bash# by Wuboxiaorm-rf Checkconfig.diff checkconfig.error Checkconfig.result linenum.txt checkConfig.resfiles= ' Find $1/src/main/resources/online-name ' *.properties ' #feflag: whether there is a missing profile flag Feflag=0#fdifftflag: First line hint text when there is a discrepancy in the file " Missing configuration item Check Result: "Presence of flag fdifftflag=0for I in $files;d o checkfile=${i/online/" $ "} 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 "Missing configuration item Check results:" 1>> Checkconfig.diff Fdifftflag=1 fi fdiflag=0 Cat $i | Grep-v "^#" |  Grep-v "^$" | While the read line does 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 donelostfilenum=$ (cat Checkconfig.error | wc-l) echo-e "\e[1;31m" $ "missing" $lostfilenum "Profile \e[0m" echo-e "\c" filelines= 1if [$lostfilenum-ne 0];then# echo-e "Profile: \c" Cat Checkconfig.error |  While the read line does if [$filelines-eq "$lostfilenum"];then echo-e $line break fi Echo -E $line ", \c" ((filelines++)) Donefiecho "" chkfilelines=$ (Cat Checkconfig.diff | WC-L) #echo "Missing configuration entry is $chkfilelines" alllostitem=$ (grep-v '. Properties ' Checkconfig.diff | wc-l) sed-i ' 1s/^.*/' "$" ' missing ' $ ((alllostitem-1)) ' Configuration item/g ' Checkconfig.diffecho-e "\e[1;31m" $ ((alllostitem-1)) "Configuration Item \e[0m" 1>> Checkconfig.resif [$chkfilelines-eq 1];then echo "No configuration Missing" 1>> Checkconfig.diff cat Checkconfig.diffelse Linecnt=1 Cat Checkconfig.diff | awk ' nr>1 ' | While the read line does result=$ (echo $line | grep "Properties") ((linecnt++)) if [! "$result" x = = "" x];then echo $linecnt 1>>linenum.txt fi done echo $ ((chkfilelines+1)) 1>>lin Enum.txt start=$ (cat linenum.txt | awk ' Nr==1 ') Cat Linenum.txt | awk ' nr>1 ' | While the read end do sed-i "$start" ' s/$/& Missing ' $ ((end-start-1)) ' Configuration item/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 the read eachline do if [$linecount-lt $ ((end-start-1))];then echo-e $eachline ", \c" 1>>c       Heckconfig.res else echo-e $eachline 1>>checkconfig.res fi ((linecount++)) done Start= $end echo "" 1>>checkconfig.res done fi#cat checkconfig.diffcat checkCONFIG.RESRM-RF check.result checkconfig.diff checkconfig.error linenum.txt checkconfig.res 

Effect:

Mother of an egg, wrote a fried chicken trash script, also drunk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.