Search code examples
shellubuntucron

Renew certificates by running script as cronjob


I need to renew my Let's encrypt certificates, which I do like this:

$ sudo docker stop nginx
$ sudo docker run -it --rm -p 443:443 --name certbot -v /etc/letsencrypt:/etc/letsencrypt -v /var/log/letsencrypt:/var/log/letsencrypt quay.io/letsencrypt/letsencrypt:latest renew
$ sudo docker start nginx

I have run these commands regulary, so I would like to create a cronjob. So far I created this file:

$ sudo nano /opt/letsencrypt.sh 

with this content:

#!/bin/sh
sudo docker stop nginx
sudo docker run -it --rm -p 443:443 --name certbot -v /etc/letsencrypt:/etc/letsencrypt -v /var/log/letsencrypt:/var/log/letsencrypt quay.io/letsencrypt/letsencrypt:latest renew
sudo docker start nginx

To add this file to the cronjobs I did:

$ sudo nano /etc/crontab

5 8 * * 6   root /opt/letsencrypt.sh

But nothing is happening at all. No error, no action. What am I doing wrong?

Would be great if the job could be logged, so I can see when it was running...


Solution

  • Have you made your script executable?

    If not, try chmod +x /opt/letsencrypt.sh