How to auto re-new letsencrypt certificate for a website every 3 months using cron?

I update it manually using this command

sudo systemctl stop nginx
sudo certbot certonly --standalone -d $url -d www.$url --email main@$url
sudo systemctl start nginx

This works fine, but it’s manual. If I create a bash script with this code and a cron task which I’ll call once in [80…89] days, will it work as I expect? With no hidden issues?

Note: this works fine when doing it manually - by hands. I only want to automate it using cron, in a simple way, without overcomlecating it.

No third-party libraries and tools.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

If you are using Certbot it should already be setup to auto renew. I’m using Ubuntu 16.04 & nginx, followed the instructions to setup certbot, and my certs have been auto renewing.

Use this link to find instructions for your stack:

Try Certbot from the same organization. It has an autorenew option.