Skip to content

Instantly share code, notes, and snippets.

@henrik242
Last active December 17, 2015 18:49
Show Gist options
  • Save henrik242/5655890 to your computer and use it in GitHub Desktop.
Save henrik242/5655890 to your computer and use it in GitHub Desktop.
Checks for upcoming expiry of SSL certificates, e.g. HTTPS or LDAPS. Useful for cron jobs and server monitoring.
#!/bin/bash
SERVER=my.example.com:443
WARNDAYS=30
EXPIRE=$(openssl s_client -connect $SERVER 2>/dev/null </dev/null | openssl x509 -noout -enddate | cut -d= -f2)
DAYS=$((( $(date --date "${EXPIRE}" +%s) - $(date +%s) ) / 86400));
[ $DAYS -lt $WARNDAYS ] && echo "WARNING: SSL certificate for $SERVER expires in $DAYS days"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment