0

I want to have a cron job that will: a. Run a python file (test.py) every minute. b. Log its output and errors to a file that I can debug.

My test.py path:

/root/my_project/my_project/warehouse/test.py

My test.py code:

print('cron job test')

Empty txt file (path) where I want to save output of the script:

/root/my_project/out.txt

My virtual environment path:

/root/my_project/my_project_venv/

My cron job line (in /var/spool/cron/crontabs/root)

* * * * 0 cd /root/my_project/my_project/ && /root/my_project/my_project_venv/bin/python /root/my_project/my_project/warehouse/test.py >> /root/my_project/out.txt 2>&1

Antoher cron job attempet (in /var/spool/cron/crontabs/root)

* * * * 0 /root/my_project/my_project_venv/bin/python /root/my_project/my_project/warehouse/test.py >> /root/my_project/out.txt 2>&1

However, it does not run, or at least I can not see that is running. When running from the command line it is working, I can see the logs in "out.txt". When running /bin/sh and then executing /bin/sh it is working - I can see the logs in "out.txt".

When running as a cron job I think this is not run since I can not find any logs about it. I checked /var/mail/root to check from mails, but nothing. Also checked /var/log/cron.log and nothing appears.

Any idea how to make this work? Or to debug this properly?

IdoS
  • 214
  • 1
  • 3
  • 13

0 Answers0