Occasional virtualenv: command not found

certbot-auto is setup to run every 12 hours via cron and usually runs without issue. But twice in the last two months, certbot-auto will exit with the below virtualenv error, and cron sends me a failure email. I'd like to see if there is a reason for these failures or if we should just ignore them.

First failure happened on Jan 3rd, and second on Jan 25th.

My domain is: syr.criticallink.com

I ran this command: sudo /etc/letsencrypt/certbot-auto renew -q

It produced this output:

/etc/letsencrypt/certbot-auto: line 1004: virtualenv: command not found

My web server is (include version):

The operating system my web server runs on is (include version):
$ lsb_release -d
Description: Ubuntu 16.04.5 LTS

I can login to a root shell on my machine (yes or no, or I don't know): yes

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot):
$ sudo /etc/letsencrypt/certbot-auto --version
certbot 0.30.1


Can you please check if virtualenv is installed?
Also, what version of python are you using?

Thank you

It would have to be installed for the tool to work most of the time.

 $ which virtualenv
 $ virtualenv --version
 $ python --version
Python 2.7.12

Just to be sure, is that exactly how it is shown with:
crontab -l

 $ sudo crontab -l
# Every 12 hours check for letsencrypt renew
0 */12 * * * /etc/letsencrypt/certbot-auto renew -q

A coworker pointed out that virtualenv is installed in several ways.

which virtualenv --> /usr/local/bin/virtualenv
dpkg --listfiles virtualenv --> /usr/bin/virtualenv [which does not exist ]

 $ pip list | grep virt
virtualenv                   16.0.0               
virtualenv-clone             0.3.0                

[/usr/local/bin/virtualenv is installed via pip]

dpkg --get-selections|grep virtualenv

python-virtualenv                               install
python3-virtualenv                              install
virtualenv                                      install

Which I think is throwing off the script. I think it sees that virtualenv package is installed and expects virtualenv to be in the path, but it is in /usr/local/bin instead and it cannot find it. I don’t think /usr/local/bin is in the PATH for root crontab.

Strangely this seems to work most of the time

1 Like

Updated cron entry to specify the /usr/local/bin. Quick tests look promising.

# Every 12 hours check for letsencrypt renew
0 */12 * * * PATH=$PATH:/usr/local/bin /etc/letsencrypt/certbot-auto renew -q
1 Like

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