Skip to content

Instantly share code, notes, and snippets.

@ahmedelgabri ahmedelgabri/
Last active May 9, 2017

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
# Auto renew Let’s Encrypt certs, two times a day at a random minute.
0 */12 * * * sleep $[($RANDOM % 60) + 1]m; /root/certbot/certbot-auto renew --quiet --no-self-upgrade

This comment has been minimized.

Copy link

tareksamni commented Oct 23, 2016

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


This comment has been minimized.

Copy link

michielrensen commented Nov 24, 2016

Nice touch on the random minute, but why?
I use this on my VPS, works like a charm:


This comment has been minimized.

Copy link
Owner Author

ahmedelgabri 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.