shell脚本批量删除harbor镜像仓库脚本

仓库版本是版本 v1.8.1

#!/bin/bash

#12.txt是仓库名字
#13.txt是月份
A=`cat 12.txt`
B=`cat 13.txt`

#X=`curl    -s -u admin:harbor123 https://192.168.10.12/api/repositories/scf/scf_financialinstitutions/tags/   -k  |grep 201910  |awk -F ":" '{print $2}' | sed 's/\"//g' | sed 's/\,//g' | sort -r  |head -n 1 `

#Z=`curl    -s -u admin:harbor123 https://192.168.10.12/api/repositories/scf/scf_financialinstitutions/tags/   -k  |grep 201910  |awk -F ":" '{print $2}' | sed 's/\"//g' | sed 's/\,//g' | sort -r  `

for i in $B
do
   for j in $A
do
   #取值tag所有 
   K=`curl  -s -u admin:harbor123 https://192.168.10.12/api/repositories/$j/tags/   -k  |grep $i |awk -F ":" '{print $2}' | sed 's/\"//g' | sed 's/\,//g'`
   #获取最大的一个tag
   J=`curl    -s -u admin:harbor123 https://192.168.10.12/api/repositories/scf/scf_financialinstitutions/tags/   -k  |grep $i  |awk -F ":" '{print $2}' | sed 's/\"//g' | sed 's/\,//g' | sort -r  |head -n 1 `
     for k in $K
       do
         if [ $k -lt $J ];then
         echo $j$k
         curl  -X DELETE   -s -u admin:harbor123 https://192.168.10.12/api/repositories/$j/tags/$k  -k
         fi
       done
    done
done
 

 

============================

北京kubernetes交流,k8s,Docker容器,群想进多多人,好交流,大家快来吧 :277473551

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页