Skip to content

Instantly share code, notes, and snippets.

@martinvirtel
Created March 31, 2017 12:18
Show Gist options
  • Save martinvirtel/472b4728314edaed8d74b14a5b8a157c to your computer and use it in GitHub Desktop.
Save martinvirtel/472b4728314edaed8d74b14a5b8a157c to your computer and use it in GitHub Desktop.
Letsencrypt: Send E-Mail if certificate validity is less than 10 days
#! /bin/bash
LOG=/tmp/letsencrypt-renewal-attempt
/usr/local/sbin/certbot-auto renew >$LOG 2>&1
service nginx reload >>$LOG 2>&1
#
# Check SSL Certificate is valid for at least $DAYS
#
DAYS=10
HOST=werkzeugkasten.dpa-newslab.com
openssl s_client -showcerts -connect $HOST:443 </dev/null 2>/dev/null|openssl x509 -noout -checkend $(echo $((24*60*60*$DAYS)) ) || \
cat <<__END__ | msmtp mvirtel@wherever_this_shoud_go
Subject: Certificate Check for $HOST failed
From: ubuntu@werkzeugkasten.dpa-newslab.com
$HOST SSL Certificate check failed. Certificate valitiy could be less than $DAYS days.
Message generated by $0.
Certificate Renewal Logfile:
$(cat $LOG)
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment