1

I have a server (Ubuntu 18.04) that is supposed to execute a Django management command at a certain interval. (every day at 16:30) I have setup jobs like this before, using cron but for some reason the server fails to execute my cronjob.

The line that I am trying to run is as follows, its using the executable of a python virtualenvironment to run a Django management command.

30 16 * * * /home/username/project/venv/bin/python3 /home/username/project/DjangoProjectName/manage.py process_data >> /home/username/crontaak.log

When I run the command directly from the terminal it all works well (including the log file). Cron also seems to work as I added the following cronjob as a test and it worked as expected.

* * * * * date > /home/username/crontestrun

I also made sure that the script had a blank line at the end, as I found some posts suggesting that as a possible cause for problems.

I checked the crontabs of my other projects with a simular (working) setup and I could not find any mistakes / differences, (except that those jobs run on servers running ubuntu 16.04).

Does anyone here have an idea what is wrong with my setup here?

4
  • 1
    In the terminal use: echo $PATH. I suspect when cron is running it doesn't know all your paths that allows your python script work in the terminal. If so the solution is to create a bash script that calls the python script. Before doing so however it executes PATH=new-paths:$PATH. Commented Dec 30, 2018 at 16:05
  • That was totally it! Thanks for the assist!
    – Jasper
    Commented Dec 30, 2018 at 17:00
  • @WinEunuuchs2Unix Please don't post answers as comments. If you ping me after you've answered, I'll come back and upvote! ;-)
    – Fabby
    Commented Dec 30, 2018 at 17:16
  • @Fabby After suitable chastising I've posted an answer :) Commented Dec 30, 2018 at 17:19

1 Answer 1

2

In the terminal use:

echo $PATH

When cron is running it doesn't know all your paths that allows your python script work in the terminal.

The solution is to create a bash script that calls the python script. Before doing so however it executes:

PATH="new-paths:$PATH"

You must log in to answer this question.

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