Skip to content

Instantly share code, notes, and snippets.

@felvis
Forked from radiofrequency/delete_expired_certs.sh
Created April 16, 2021 11:31
Show Gist options
  • Save felvis/faf19dd2114144e0f3337a678b7bcab2 to your computer and use it in GitHub Desktop.
Save felvis/faf19dd2114144e0f3337a678b7bcab2 to your computer and use it in GitHub Desktop.
delete expired lets encrypt certificates
unix_todate=$(date -d "${todate}" "+%s")
getDomainName() {
echo $1 | cut -d'/' -f 5
}
for pem in /etc/letsencrypt/live/*/cert.pem; do
if [ $(date --date="$(openssl x509 -enddate -noout -in "$pem"|cut -d= -f 2)" "+%s") -le $unix_todate ];
then
domain=$(getDomainName $pem)
printf 'deleting cert %s expired: %s\n' \
"$domain" \
"$(date --date="$(openssl x509 -enddate -noout -in "$pem"|cut -d= -f 2)" --iso-8601)"
certbot delete --cert-name $domain
fi
done | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment