码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本实例

时间:2018-03-22 15:02:11      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:bash   special   AC   ++   amp   col   cfile   function   div   

#!/bin/bash

SRC_PATH=/mnt/source/xx/xx

# Merge all spec file for quick search
mergedSpec="./allSpec-"$(date +%Y%m%d).txt

function merge_all_specs(){
    allSpec=$(find $SRC_PATH -name *.spec)
    for specFile in $allSpec
    do  
        specName=$(basename $specFile)
        specPrefix=${specName%.*} 
        #echo $specName, echo ${specName%.*}
        prefix="${specPrefix}":"${specFile}:"
        #echo $prefix
        prefix=${prefix//\//\\\/}
        #echo $prefix
        cat $specFile | sed s/^/‘"$prefix"‘&/g >> $mergedSpec 
    done
}

if [ ! -f "$mergedSpec" ]; then
    merge_all_specs
fi

resultFile=$1-confirmed
:>$resultFile

cat $1 | while read LINE
do
    #echo $LINE | grep -ri CVE
    #if [ $? -ne 0 ]
    #then
    #    continue
    #fi

    sa=`echo $LINE | awk {print $1}`
    cves=`echo $LINE | awk {for (i=2 ;i<=NF;i++) printf $i " "}`

    for cve in $cves
    do
        #echo $cve
        grep -i $cve $mergedSpec >/dev/null 2>&1
        if [ $? -ne 0 ]
        then
            echo -e "$sa $cve:\t待确认"
            echo -e "$sa $cve:\t待确认" >> $resultFile
        else
                record=$(grep -ri $cve $mergedSpec)
        specFile=`echo ${record} | awk -F : {print $2}`

        comm_dir=`dirname $specFile`
                comm_specfile=`basename $specFile`

        comm=${comm_specfile%.*}
        #echo ${comm_dir}"->"${comm_specfile}

        if [ ! -d "${comm_dir}" ]
                then
                     continue
                fi
pushd ${comm_dir} >/dev/null 2>&1

                if [ -d ".git" ]
                then
                     commitmsg=`git blame ${comm_specfile} | grep -i $cve | head -1 | awk {print $1}`
                     #echo "----ID---"${commitmsg}
                else
                     echo -e "$sa $cve:\tNo find .git"
             popd >/dev/null 2>&1
                     continue
                fi
popd >/dev/null 2>&1

                # Remove all space
            version=`echo $version | sed s/[[:space:]]//g`
            release=`echo $release | sed s/[[:space:]]//g`

                # Special Cases


            echo -e "$sa $cve:\tMerged","\t"${comm%%:*}-${version##*:}-${release##*:}
            echo -e "$sa $cve:\tMerged","\t"${comm%%:*}-${version##*:}-${release##*:} >> $resultFile
        fi
    done
done

 

shell脚本实例

标签:bash   special   AC   ++   amp   col   cfile   function   div   

原文地址:https://www.cnblogs.com/stellar/p/8623789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!