0

I created a CRON Job to run a Python script at 11.45 everyday. However, when I tested , I see that python script is not getting executed:

45 11 * * * /usr/bin/python2.7 /home/user/Documents/Example/main.py

I think that the problem is with python installation directory since I have multiple python installations and I am not sure which is correct one:

To check python installation, I used following command:

whereis python

Output:

python: /usr/bin/python3.6m /usr/bin/python2.7-config /usr/bin/python
/usr/bin/python3.6 /usr/bin/python2.7 /usr/lib/python3.7 
/usr/lib/python3.6 /usr/lib/python2.7 /etc/python /etc/python3.6 
/etc/python2.7 /usr/local/lib/python3.6 /usr/local/lib/python2.7 
/usr/include/python3.6m /usr/include/python2.7 /usr/share/python 
/usr/share/man/man1/python.1.gz

I have added executable permissions to the Python script and its parent directory:

chmod a+x /home/user/Documents/Example/main.py

Note: I want to use python 2.7 for execution of the script. Is there anything that I am doing wrong

Tjs01
  • 457
  • 2
  • 8
  • 14
  • 1
    can you post the result of `grep CRON /var/log/syslog` ? Obviously remove private information, if any. – Manuel Fedele Mar 20 '19 at 12:14
  • 1
    Have you tried running the command you added to cron i.e. does this execute `/usr/bin/python2.7 /home/user/Documents/Example/main.py` when you run it in your command line? Also to find full path of shell command use `which`, `whereis` is used to `locate the binary, source, and manual page files for a command` – bagljas Mar 20 '19 at 12:14
  • I think the correct path for python 2.7 is **/etc/python2.7**. Try executing the script before iinserting it on crontab. `/etc/python2.7 /home/user/Documents/Example/main.py` or even `/usr/bin/python2.7 /home/user/Documents/Example/main.py` and post the output. – Amith Raj Shetty Mar 20 '19 at 12:27
  • What is your script trying to do?, and how do you know that it is not executing? – Zubda Mar 20 '19 at 14:03
  • No MTA installed, discarding output: This is the rror I get when it tries to execute the job @Miles Davis – Tjs01 Mar 20 '19 at 14:35
  • @ bagljas . I did try this. It works fine for both the commands – Tjs01 Mar 20 '19 at 14:36
  • @Tjs01 are you able to execute something simpler for example: `*/1 * * * * echo "testing" >> /tmp/test.txt` This will run every minute and append `testing` to `/tmp/test.txt` file (don't forget to remove this from your crontab after testing). If this works, problem might be with `main.py`. – bagljas Mar 20 '19 at 20:58
  • Yes. I was able to run that. I tried creating a simple txt file initially. That's where I realized the problem was with Python – Tjs01 Mar 21 '19 at 09:16
  • @Tjs01 can you post minimal `main.py` script which shows this issue, so we can reproduce the issue? – bagljas Mar 21 '19 at 12:41

0 Answers0