I installed certbot from pip3:
# pip3 freeze|grep -i certbot certbot==1.5.0 certbot-apache==1.5.0 certbot-dns-digitalocean==1.5.0 I can run certbot from the command line as root, but I configured crontab to run perl -e 'sleep int(rand(1800))' && certbot -q renew as root twice a week, and I get this error message by email:
/bin/sh: 1: certbot: not found If I type whereis certbot at the command line I get this result:
certbot: /usr/local/bin/certbot Why doesn't certbot run from crontab successfully?
I'm using Ubuntu 18.04.
2 Answers
You need to use fill paths within crontab while your executable doesn't belong to the cron's PATH, which by default includes only /bin and /usr/bin. So your cronjob should look like:
* * * * * perl -e 'sleep int(rand(1800))' && /usr/local/bin/certbot -q renew You could customize the cron's environment as it is shown at the last point here, but IMO it is better to change your scripts (and cronjobs) to work with the default environment, thus they will be more portable, when you are setup a new system, etc.
TL:DR For Ubuntu 20.04 users, don't forget that certbot is installed with snapd.
This answer and question put me on the right path. In Ubuntu 20.04, certbot perfers snapd. I had installed by following a tutorial but had forgotten about all about snap. @Uri's whereat certbot helped to remind me that the location had changed. Either run
0 2 * * 1 /snap/bin/certbot renew
or include snap in the PATH environment variable
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/snap/bin
