Skip to content

Instantly share code, notes, and snippets.

@ahmedelgabri ahmedelgabri/README.md
Last active May 9, 2017

Embed
What would you like to do?
Cron job for automatic renewal of Let’s Encrypt certs, it should run twice a day at a random minute.

This is a cron job entry to that will auto renew your Let's Encrypt certificate automatically by running 2 times a day evey 12 hours on a random minute.

You can add a cron job entry by running this command

$ crontab -e

Then past the following snippit in that file, Note that lines 1-3 might not be required at all. Make sure your check the link to the thread regarding this.

I'm not a DevOps/Server guy, so any improvements are highly appreciated.

# This is required for vixie-cron (man cron)
# Check http://superuser.com/questions/264528/problem-with-random-in-crontab/264541#264541
SHELL=/bin/bash
# Auto renew Let’s Encrypt certs, two times a day at a random minute.
# https://certbot.eff.org/
# http://crontab.guru/#0_*/12_*_*_*
# http://stackoverflow.com/a/16289693/213124
# http://blog.buberel.org/2010/07/howto-random-sleep-duration-in-bash.html
0 */12 * * * sleep $[($RANDOM % 60) + 1]m; /root/certbot/certbot-auto renew --quiet --no-self-upgrade
@tareksamni

This comment has been minimized.

Copy link

commented Oct 23, 2016

You can also replace SHELL=/bin/bash with #!/bin/bash

@michielrensen

This comment has been minimized.

Copy link

commented Nov 24, 2016

Nice touch on the random minute, but why?
I use this on my VPS, works like a charm: https://github.com/hlandau/acme

@ahmedelgabri

This comment has been minimized.

Copy link
Owner Author

commented May 9, 2017

@michielrensen will check it! (I hate that gists doesn't have any kind of notifications)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.