扫描文件版本

#! /bin/bash
function judge()  
{
    K8sCluster=$1
    #Dir=webapps/ROOT/WEB-INF/lib/
    Dir=$2
    FileName=$3
    FileFullName=$4
    rm -f /tmp/detail.list
    rm -f /tmp/app.list
    for pod in $(kubectl get pod | grep dmo | awk '{print $1}')
    do
        jar=$(kubectl exec -it $pod -- sh -c "ls $Dir | grep $FileName" | grep $FileName)
    #    if [ -z "$jar" ]; then
    #        echo $jar"  "null
    #    fi
        if [ -n "$jar" ]; then
            count=$(echo $jar | grep $FileFullName | wc -l)
            if [ 0 -eq $count ]; then
                image=$(curl -G -d "k8sCluster=$K8sCluster" -d "type=pod" -d "name=$pod"  http://172.37.66.177:30380/k8s-openapi/apiMonopolistic/findImage)
         	    app=$(echo $image | awk -F"/|:" '{print $3}')
         	    detail=$(echo $app"::::"$image"::::"$jar)
                echo $app >> /tmp/app.list
                echo $detail >> /tmp/detail.list
            fi
        fi
    done
    
    #cp jar.json /tmp
    #rm -f /tmp/test
    #awk 'NR == 1 {p = $0} NR > 1 {print p; p = $0} END{printf p} ' /tmp/detail.list > /tmp/detailNew.list
    
    for app in $(cat /tmp/app.list | sort | uniq)
    do
        sed -i "s#result#${app}|result#g" /tmp/jar.json
    done
    
    cat /tmp/detail.list | sort | uniq | while read originline
    do
    	# ^M的输入方式是 Ctrl + v ,然后Ctrl + M
        line=$(echo $originline | sed -e 's/
//g')
    
        APP=""
        IMAGE=""
        JAR=""
        eval $(echo $line | awk -F"::::" '{printf("APP=%s;IMAGE=%s;JAR=%s",$1,$2,$3)}')
    #    sed -i "s#result#${APP}|result#g" /tmp/jar.json
    
        sed -i "s#DESCdesc#${line}|DESCdesc#g" /tmp/jar.json
    done
     
    sed -i "s#|result##g" /tmp/jar.json
    sed -i "s#result##g" /tmp/jar.json
    
    sed -i "s#|DESCdesc##g" /tmp/jar.json
    sed -i "s#DESCdesc##g" /tmp/jar.json
    
    curl -H "Content-Type: application/json" -X POST -d @/tmp/jar.json http://172.37.66.177:30380/alert/common/alert
}
function main(){
    CLUSTER=$1
    echo $CLUSTER
    curl -G -d "categoryNo=CONFIG" -d "codeNo=shell/alert/file_version"   http://172.37.66.177:30480/rpp/apiMonopolistic/code/getCacheValue | grep $CLUSTER | grep -v "#" > /tmp/req.list
    cat /tmp/req.list | while read req
    do
        cp jar.json /tmp
        JAR=$(echo $req | awk '{print $4}')
        sed -i "s#CLUSTERcluster#${CLUSTER}#g" /tmp/jar.json 
        title="容器扫描结果: "$CLUSTER"环境,jar版本要求:"$JAR" 需要调整的有:"
        sed -i "s#TITLEtitle#${title}#g" /tmp/jar.json 
        judge $req
    #judge ningxia-dev3 /usr/local/tomcat/webapps/ROOT/WEB-INF/lib bizcloud-framework-mongo-dao bizcloud-framework-mongo-dao-2.1.18-SNAPSHOT.jar
    done
}

main $1
{
    "cluster":"CLUSTERcluster",
    "type": "image",
    "title": "TITLEtitle",
    "text":  "result",
    "desc": "DESCdesc"
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值