Cron not working?


need some assistance or explanation. I try to have a complete automatic renewal process, but it seems that it is not working with cronjob.

For some test purpose I have defined the follwoing cronjob, to see if the job will be executed every 15 minutes. But I just can see the manual runs in the logs.

*/15 * * * * certbot renew --standalone --pre-hook "service nginx stop" --post-hook "service nginx start" >> /var/log/letsencrypt/letsencrypt.log

If I run the command certbot renew --standalone --pre-hook "service nginx stop" --post-hook "service nginx start" >> /var/log/letsencrypt/letsencrypt.log manually it works and I can see new created logfiles, but not the ones that should be created by crontab:

root@winter-pi:/var/log/letsencrypt# ls -alF | grep "Apr 26"
drwx------  2 root root 12288 Apr 26 13:07 ./
drwxr-xr-x 11 root root  4096 Apr 26 12:34 ../
-rw-r--r--  1 root root  1635 Apr 26 13:07 letsencrypt.log
-rw-r--r--  1 root root  1823 Apr 26 13:07 letsencrypt.log.1
-rw-r--r--  1 root root  1635 Apr 26 11:54 letsencrypt.log.2
-rw-r--r--  1 root root 49603 Apr 26 11:54 letsencrypt.log.3
-rw-r--r--  1 root root 15111 Apr 26 00:00 letsencrypt.log.4

Any idea why this is happen?

Kind regards

Hi @nephilim,

maybe try to set User (Same User as you tried your command manually and it worked) and a fullpath of certbot.

For example:

*/15 * * * * root /usr/bin/certbot renew --standalone --pre-hook "service nginx stop" --post-hook "service nginx start" >> /var/log/letsencrypt/letsencrypt.log

To see your path to certbot you can use this command: which certbot

greetz Sm3rT

I tested it. And it seems that it doesn’t matter which form is used. I now checked syslog and can see that the command looks like it will be executed:

Apr 26 16:30:01 winter-pi CRON[7453]: (root) CMD (/var/www/scripts/ >> /var/log/letsencrypt/letsencrypt.log)

But why isn’t it creating a logfile of these actions every 15 minutes?

Kind regards

Hi @nephilim,

Could you please explain how did you create this cronjob?.


Hej sahsanu

sorry for the late response. I did it several ways. First I copied/pasted it from this website. Then I typed it manually. Usually I use sudo crontab -e or as root user crontab -e.

Not sure if I answered your question right.

But I found a workaround. Based on your replies here I have disabled certbot.timer and added the following line to my crontab:

30 3 * * 1 systemctl start certbot.service

I have tested it this way:

*/15 * * * * systemctl start certbot.service

and could find the following in the logs:

Apr 27 18:15:01 winter-pi systemd[1]: Starting Certbot...
Apr 27 18:30:01 winter-pi systemd[1]: Starting Certbot...
-rw-r--r--  1 root root  1635 Apr 27 18:30 letsencrypt.log
-rw-r--r--  1 root root  1635 Apr 27 18:15 letsencrypt.log.1

Anyhow, I would like to know why my previous setup did not work.

Thank you much in advance.

Kind regards

As @Sm3rT already recommended, you should use the full path to the executable. Regarding the reason you are not seeing the log file created, keep in mind that by default, cron will use sh shell to execute your command instead of bash so things like redirection could not work as you expect, try the following syntax (just added the full path to certbot and 2>&1 at the end of command).

*/15 * * * * /usr/bin/certbot renew --standalone --pre-hook "service nginx stop" --post-hook "service nginx start" >> /var/log/letsencrypt/letsencrypt.log 2>&1


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.