|
I have a Python 2.7 script,test.py, that I wish to run via crontab. Its only function is to print the Python version number. #!/usr/bin/env python2.7 import sys print sys.version It did not work, so I created an sh script named crontestscript to run it 5 ways. First using the default Python, then versions 2.5, 2.6, 2.7, and lastly the 2.7 version specified within the test.py script. #!/bin/sh echo "crontestscript starting =====" >> $HOME/cron/crontest.log date +"%Y-%m-%d %T" >> $HOME/cron/crontest.log python $HOME/cron/test.py >> $HOME/cron/crontest.log python2.5 $HOME/cron/test.py >> $HOME/cron/crontest.log python2.6 $HOME/cron/test.py >> $HOME/cron/crontest.log python2.7 $HOME/cron/test.py >> $HOME/cron/crontest.log $HOME/cron/test.py >> $HOME/cron/crontest.log I ran the script via the command line and set crontab to run the same script 45 minutes after the hour. The results are below. Only Python 2.4.3 runs via crontab. crontestscript starting ===== 2011-07-31 11:41:28 2.4.3 (#1, May 5 2011, 16:39:09) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] 2.5.4 (r254:67916, Nov 22 2010, 23:13:26) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] 2.6.5 (r265:79063, Nov 23 2010, 02:02:03) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] 2.7.1 (r271:86832, Dec 1 2010, 06:29:57) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] 2.7.1 (r271:86832, Dec 1 2010, 06:29:57) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] crontestscript starting ===== 2011-07-31 11:45:01 2.4.3 (#1, May 5 2011, 16:39:09) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] Is there way to access Python 2.7 via crontab? |
|
The reason " The fact that cron uses a different environment from your normal shell account is mentioned in our own documentation and elsewhere on the web, eg: You can use Another solution would be to set your PATH environment variable at the top of your crontab, eg:
Hope that helps! |