(x-posted from StackOverflow)
I have set up cron to execute the following command for django-cron (django 1.10.5, python 3.5, anaconda 4.2.0) in ubuntu 16.04:
PATH=/user/project/projectname/website * * * * * ./manage.py runcrons "app.crons.RunCronJob"
Here is my file tree, which is located directly under the highest level of the remote site (
|-- user | |-- project | | |-- projectname | | | |-- website | | | | |-- file.txt | | | | |-- manage.py | | | | |-- app (a django app) | | | | | |-- crons.py
RunCronJob is a cronjob within
crons.py that appends a line to
/website. When I enter the
/website directory and manually do
./manage.py runcrons "app.crons.RunCronJob", it works just fine. However, when the cronjob I have set up is run, it does not append anything to my text file. I have verified that the cron task is running every minute with both
grep cron /var/log/syslog a mailing service, but the data I receive doesn't seem to tell me anything useful about why it isn't working.
(Note for python: I have added
os.chdir(os.path.dirname(sys.argv)) to the top of my
crons.py to ensure that the text file gets written to in the correct directory, no matter where the command is run from. E.g., running
website/manage.py runcrons "app.crons.RunCronJob" from
/projectname is working for me as well. For this reason, I don't suspect my issue is related to django, the django-cron library or python.)
I have viewed some other answers which discuss some common problems with cron and have tried my best to fix any problems: my crontab has a newline at the end, I have set my timezone (though this should not affect my cronjob),
pgrep cron returns a number, I have set the permissions for my text file, I have restarted cron many times, etc.
Although I have also tried to properly set my environment paths, I suspect that some part of it is still wrong. I tried various things like adding
/home in front of
/user, removing the dot and/or slash in front of
manage.py, and adding the absolute filepath in front of my command, all to no avail.
Even though I think my suspect is in how I am setting my paths, the error could still be somewhere else in my project. What issue am I overlooking, or how should I diagnose it?