Shell 用于删除 AWS 过期证书的脚本
Shell Script for AWS Expired Certs to Delete
正在尝试编写脚本来查找和删除过期的 aws 证书
#!/bin/bash
for c in $(aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn' --output text)
do aws acm describe-certificate --certificate-arn $c --query 'Certificate.[CertificateArn,DomainName,Status,NotAfter]'
done
然后我得到了这个输出
"arn:aws:acm:us-east-1: somenumbers "*blabla.com", "ISSUED", "2020-11-10T12:00:00+00:00"
如果您需要删除 aws 中的过期证书。这是 bash 脚本!
这个脚本在我的环境中完美运行
#!/bin/bash
#set -x
echo ""
echo "--> Displaying todays date"
echo ""
sleep 2
DATE=$(date '+%Y-%m-%dT%H:%M:%S+00:00')
echo "--> Todays date is ----- "$DATE" ------ "
echo ""
echo "--> Collecting certs IDs and parsing EXPIRED ones into json file."
echo "-----------------------------------------------------------------"
for c in $(aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn' --output text); do
aws acm describe-certificate --certificate-arn "$c" --output json | jq --arg date "$DATE" -r '.| select(.Certificate.NotAfter <= $date ) | .Certificate.CertificateArn' >> certs2.json
echo "Processing --> $c"
#Looping through each line of certs2.json to collect arn of each cert and then deleting it
done
while read -r line; do
aws acm delete-certificate --certificate-arn "$line" --output text
echo "Deleting Expired Certificate --> "$line" "
done <certs2.json
#echo "Deleting certs2.json File"
#rm -rf certs2.json
echo "---------------------All Expired Certificates are deleted!-------------------------"
正在尝试编写脚本来查找和删除过期的 aws 证书
#!/bin/bash
for c in $(aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn' --output text)
do aws acm describe-certificate --certificate-arn $c --query 'Certificate.[CertificateArn,DomainName,Status,NotAfter]'
done
然后我得到了这个输出
"arn:aws:acm:us-east-1: somenumbers "*blabla.com", "ISSUED", "2020-11-10T12:00:00+00:00"
如果您需要删除 aws 中的过期证书。这是 bash 脚本! 这个脚本在我的环境中完美运行
#!/bin/bash
#set -x
echo ""
echo "--> Displaying todays date"
echo ""
sleep 2
DATE=$(date '+%Y-%m-%dT%H:%M:%S+00:00')
echo "--> Todays date is ----- "$DATE" ------ "
echo ""
echo "--> Collecting certs IDs and parsing EXPIRED ones into json file."
echo "-----------------------------------------------------------------"
for c in $(aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn' --output text); do
aws acm describe-certificate --certificate-arn "$c" --output json | jq --arg date "$DATE" -r '.| select(.Certificate.NotAfter <= $date ) | .Certificate.CertificateArn' >> certs2.json
echo "Processing --> $c"
#Looping through each line of certs2.json to collect arn of each cert and then deleting it
done
while read -r line; do
aws acm delete-certificate --certificate-arn "$line" --output text
echo "Deleting Expired Certificate --> "$line" "
done <certs2.json
#echo "Deleting certs2.json File"
#rm -rf certs2.json
echo "---------------------All Expired Certificates are deleted!-------------------------"