Skip to content

Instantly share code, notes, and snippets.

@Sean-Bradley
Last active October 20, 2023 17:37
Show Gist options
  • Save Sean-Bradley/7826495e54f52865dd1d0af14a6570ea to your computer and use it in GitHub Desktop.
Save Sean-Bradley/7826495e54f52865dd1d0af14a6570ea to your computer and use it in GitHub Desktop.
A script to return the number of days before a SSL certificate expires. Visit https://sbcode.net/zabbix/system-run/ for instructions
data=`echo | openssl s_client -servername $1 -connect $1:443 2>/dev/null | openssl x509 -noout -enddate | sed -e 's#notAfter=##'`
ssldate=`date -d "${data}" '+%s'`
nowdate=`date '+%s'`
diff="$((${ssldate}-${nowdate}))"
echo $((${diff}/86400))
@franko108
Copy link

Thanks, works like a charm.
Particularly useful if we have some protected hosts and public check of SSL expiration is not possible. Script is doing it locally on own host, nice.
All the best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment