Skip to content

Instantly share code, notes, and snippets.

@zafergurel
Created January 3, 2020 20:47
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 zafergurel/e1023b7856ad97a1349ef4816adce070 to your computer and use it in GitHub Desktop.
Save zafergurel/e1023b7856ad97a1349ef4816adce070 to your computer and use it in GitHub Desktop.
Check ssl certificate expiration
#!/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