Skip to content

Instantly share code, notes, and snippets.

@jeremysherriff
Last active October 21, 2018 03:16
Show Gist options
  • Save jeremysherriff/474e5f1e2d690cdbad5f0afa1df437aa to your computer and use it in GitHub Desktop.
Save jeremysherriff/474e5f1e2d690cdbad5f0afa1df437aa to your computer and use it in GitHub Desktop.
BASH script to check nearing expiry of SSL certs and send email notification
#!/bin/bash
# Get ssl-cert-check from https://github.com/Matty9191/ssl-cert-check
# Check that the below script lines use the right cert locations
# and email parameters
RENEWAL_DAYS=14
TMPFILE=`mktemp -t email.XXXXXXXXXX`
ISEXPIRING=false
for CERT in $(ls -1R /etc/letsencrypt/live/*/cert.pem)
do
/opt/ssl-cert-check/ssl-cert-check -d $CERT -x $RENEWAL_DAYS | grep -i expiring >> $TMPFILE && ISEXPIRING=true
done
if [[ $ISEXPIRING == true ]]; then
cat $TMPFILE | sendemail -f "PrettySenderName"\<sender@email.com\> -t alerts@email.com -u "SSL cert(s) expire soon" -o tls=no -s mail.gateway.local:25 -q
fi
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment