Home Computers Operating Systems cron and /usr/bin/env
cron and /usr/bin/env PDF Print E-mail
Written by Gordon Tillman   
Thursday, 22 January 2009 15:49

I ran into a minor problem recently when running a Python script with the cron facility. It was a simple oversight (and I know better) but I thought it may serve as a useful reminder.

Cron jobs run with a very small PATH. By default, it is /usr/bin:/bin. This is not normally a big deal, because you should be using full paths anyway in your scripts. But one place where that is not always followed is the shebang line at the top of a script. For example, the first line of a Python script may look like this:

#!/usr/bin/env python

Or, if you needed a particular version of Python:

#!/usr/bin/env python2.5

This is all well and good. But if, for example, python2.5 was located here: /usr/local/bin/python2.5... well that will not work in a cron job unless you override the default path. You will not receive any errors ... it just won't run. The fix in this case is just to put this at the top of your crontab file:

PATH=/usr/local/bin:/usr/bin:/bin
Last Updated on Thursday, 22 January 2009 16:00