Created
January 3, 2020 20:47
-
-
Save zafergurel/e1023b7856ad97a1349ef4816adce070 to your computer and use it in GitHub Desktop.
Check ssl certificate expiration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
gracedays=90 | |
# get domain names from a file | |
# a domain at each line | |
domain_file="domains.txt" | |
cat $domain_file | while read -a domains; | |
do | |
server=${domains[0]} | |
data=`echo | openssl s_client -connect "${server}:443" -servername "${server}" 2>/dev/null | openssl x509 -noout -enddate | sed -e 's#notAfter=##'` | |
ssldate=`date -d "${data}" '+%s'` | |
nowdate=`date '+%s'` | |
diff="$((${ssldate}-${nowdate}))" | |
if test "${diff}" -lt "$((${gracedays}*24*3600))"; | |
then | |
if test "${diff}" -lt "0"; | |
then | |
echo "The certificate for ${server} has already expired." | |
else | |
echo "The certificate for ${server} will expire in $((${diff}/3600/24)) days." | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment