Skip to content

Instantly share code, notes, and snippets.

@Ksisu
Created January 24, 2022 12:34
Show Gist options
  • Save Ksisu/86ab93e8e6617c84d1a6479c46aa4055 to your computer and use it in GitHub Desktop.
Save Ksisu/86ab93e8e6617c84d1a6479c46aa4055 to your computer and use it in GitHub Desktop.
Check ssl exp date script
#!/bin/bash
gracedays=14
result=0
for server in example.com www.example.com other-test.com; do
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."
result=2
else
echo "The certificate for ${server} will expire in $((${diff}/3600/24)) days."
if test "$result" != "2"; then
result=1
fi
fi
fi
done
if test "$result" = "0"; then
echo "All certificate valid!"
fi
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment