Crontab not executing a Python script?

前端 未结 15 1526
囚心锁ツ
囚心锁ツ 2020-11-29 20:42

My python script is not running under my crontab.

I have placed this in the python script at the top:

#!/usr/bin/python

I hav

相关标签:
15条回答
  • 2020-11-29 21:09

    It's usually because the python used by crontab is different from the one you use in the shell. The easiest way to solve this is:

    1. get the python you use in the shell:

    $ which python # it may be "python3" or something else /usr/bin/python

    1. use that specific python in crontab file:

    * * * * * /usr/bin/python test.py

    Also want to mention that using env -i /bin/bash --noprofile --norc in the shell lets you have the same environment as the one used by crontab, and this is super helpful to debug.

    0 讨论(0)
  • Try this

    * * * * * cd <directory_where_python_file_is> && bin/app etc/app_defaults.yaml
    

    There is some path issue with cron. So when you move to directory with python file, cron works like charm!

    0 讨论(0)
  • 2020-11-29 21:15

    I'd got the same problem. Despite the fact that the script executed manually was working, in crontab no options mentioned above were working at all. I've moved my script from /home/user/script_directory/ to /opt/scripts/ and it started to work. Possible cause of the problem should be the access (read) permissions to subfolder located in home directory.

    0 讨论(0)
提交回复
热议问题