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?
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 executesPATH=new-paths:$PATH
.