I need to to execute a python script for periodically for my django project.So I'm using django_crontab.

This is what crontab -e has

*/1 * * * * /home/myvenv/bin/python /home/user/myproj/manage.py crontab run b74d4d1f47748498b81b5bcf863684c3 >> /home/user/myproj/myapp/file.log

The python script should print out 'Hello' to file.log every 1 minute.

def cronSendEmail():
    return True

The log at /var/log/syslog

Jan  3 22:35:01 me CRON[24607]: (myuser) CMD (/home/myvenv/bin/python /home/user/myproj/manage.py crontab run b74d4d1f47748498b81b5bcf863684c3 >> /home/user/myproj/file.log
Jan  3 22:35:02 me CRON[24606]: (CRON) info (No MTA installed, discarding output)

This is being logged every minute, but 'Hello' is not printed. file.log is empty. Why is "Hello" not being printed? Is No MTA installed, discarding output, the key problem?

EDIT: This is django project and I'm creating the task via django-crontab in settings.py

CRONJOBS = [ ('*/1 * * * *', 'app.cronSendEmail', '>> /home/user/myproj/file.log') ]
  • 1
    Is that your complete python script? you don't appear to actually call the cronSendEmail() function Jan 3 '18 at 18:07
  • I'm calling it. This is actually a django project and I'm calling it via django-crontab in settings.py: CRONJOBS = [ ('*/1 * * * *', 'app.cronSendEmail', '>> /home/user/myproj/file.log') ]
    – Vaish MK
    Jan 3 '18 at 18:13
  • Please always add additional information directly to your question (edit) rather than in comments.
    – dessert
    Jan 3 '18 at 18:15
  • "This is being logged every minute" clearly indicated that the cron job IS running. The task is executing...it's just failing with an error message every time. Look up how to redirect STDERR to your log so you can read the error message.
    – user535733
    Jan 3 '18 at 18:41
  • Thanks so much for the STDERR advice! I had messed up the path to the python function. It works now.
    – Vaish MK
    Jan 3 '18 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.