1

I have installed Python 2.7 through mac ports, and now want to have it used in a cron job. Unfortunatly, each time the cron job gets involved, the standard Python of my machine (an iBook G4 using Tiger) which is 2.3 is involved, making my job fail.

My PATH is (from the set command)

PATH=/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin

P

How can I have my cron job be invoked with my PATH instead of the faulty one ?

  • Just start the python task with the full path to python in the cron job i.e. /opt/local/bin/python - Unless has complex dependencies this should not require path changes – user151019 Aug 8 '16 at 19:49
1

The result of the PATH variable is quite different in the cron world. Invoke the script with the full path to the python binary (e.g. /opt/local/bin/python2.7) and you should be good.

This can be examined by running env as cronjob and comparing it to the result of running env as yourself in Terminal:

user's cron env:

PATH=/usr/bin:/bin:/usr/sbin:/sbin
...
SHELL=/bin/bash
HOME=/Users/user
USER=user
PWD=/
...

compared to user's env:

PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
...
SHELL=/bin/bash
HOME=/Users/user
USER=user
PWD=/Users/user
...

Alternatively you may add the PATH to the crontab:

sudo nano /var/cron/tabs/user

In newer systems (probably ≥10.6):

sudo nano /private/var/at/tabs/user

Change

...

*       *       *       *       *       some command

to

...
PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

*       *       *       *       *       some command
  • Of course, you can change the value of PATH in your crontab. – fd0 Aug 8 '16 at 20:46
  • I just set the WAYBAC machine to 10.4, you will find crontabs in /etc/crontab. – fd0 Aug 8 '16 at 20:59
  • @fd0 Thanx for this. My VM smorgasbord only include 10.6 and newer... – klanomath Aug 8 '16 at 21:04
  • I was mistaken, /etc/crontab is the "system" crontab. User crontabs are found in /var/cron/tabs in 10.4. Source: opensource.apple.com/source/cron/cron-12.2/cron/pathnames.h – fd0 Aug 11 '16 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .