Skip to content

Instantly share code, notes, and snippets.

@adrianmihalko
Created January 13, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmihalko/fb25d7841751297f929280b060ec9706 to your computer and use it in GitHub Desktop.
Save adrianmihalko/fb25d7841751297f929280b060ec9706 to your computer and use it in GitHub Desktop.
Letsencrypt update script, restart service if success and notify with ssmtp
SERVER="Ubuntu (192.168.1.54)"
EMAIL='hello@gmail.com'
ALERTMESSAGE='/tmp/ALERTMESSAGE_cert.tmp'
if /usr/bin/openssl x509 -checkend 86400 -noout -in /etc/letsencrypt/live/my.domain.eu/fullchain.pem
then
echo "Certificate is good for another day!"
else
echo "To: $EMAIL" > $ALERTMESSAGE
echo "From: $FROM" >> $ALERTMESSAGE
echo "Subject: LetsEncrypt SSL Renew on $SERVER" >> $ALERTMESSAGE
echo "" >> $ALERTMESSAGE
echo "Certificate has expired or will do so within 24 hours!" >> $ALERTMESSAGE
echo "Start LetsEncrypt" >> $ALERTMESSAGE
/home/username/scripts/letsencrypt/letsencrypt-auto renew --renew-hook "systemctl restart unifi.service" >> $ALERTMESSAGE
/usr/sbin/ssmtp $EMAIL < $ALERTMESSAGE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment