Skip to content

Instantly share code, notes, and snippets.

@reox
Created October 19, 2014 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reox/17b7ee632b6bb8b45081 to your computer and use it in GitHub Desktop.
Save reox/17b7ee632b6bb8b45081 to your computer and use it in GitHub Desktop.
Print out information about non valid certificates and certificates that will run out in less than 30 days.
#!/bin/bash
# Show the validity of certificate files
# If the certificate will run out in less than one month, a warning is shown
# If the certificate is not valid anymore, an error message is shown
# Valid certificates are not printed out
for cert in /etc/nginx/ssl/*.crt; do
d1=$(date -d "$(openssl x509 -noout -dates -in $cert | grep notAfter | cut -d '=' -f 2)" +%s)
d2=$(date +%s)
valid=$(( (d1 - d2) / 86400 ))
if [ $valid -le 0 ]; then
echo "[ERRO] $cert is NOT VALID anymore! (since $(( $valid * -1)) days)"
elif [ $valid -le 30 ]; then
echo "[WARN] $cert will be run out in less than one month! ($valid days left)"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment