4

I am using crontab in django and my OS is ubuntu

def my_scheduled_job():
    print("1")

This is code in settings.py

CRONJOBS = [
    ('*/1 * * * *', 'stocks.cron.my_scheduled_job')
]

If I run

python3 manage.py crontab run #with hash

it runs the function and print it, but it does not run when I run server. What should I do.

It was my code in crontab

    crontab -e
*/1 * * * * /usr/bin/python3 /home/stockstelegraph/manage.py crontab run 6b918d2422a9f4fce735a3383cee6485 # django-cronjobs
1
  • 4
    Are you sure your job is not running? A job run by cron will not print to your screen. You can direct the output to a file and then view the file.
    – PonJar
    Oct 14, 2020 at 11:39

1 Answer 1

1

Your code actually works. You may be think that print("1") should appear in stdout? So it doesn't work that way, because cron doesn't use stdour and stderr for it's output. To see actual results you should point path to some log file in CRONJOBS list: just put '>> /path/to/log/file.log' as last argument, e.g:

('*/1 * * * *', 'stocks.cron.my_scheduled_job', '>> /path/to/log/file.log')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.