Running a Python Script using Cron?

落花浮王杯 提交于 2019-12-18 04:55:15

问题


I have a python script that I'd like to add to cron.

The script has +x permission on it.

How shall I add it to crontab? (say, I want it to run every minute).

Important: when I navigate (using the shell) to the script's folder, I cannot run it using "./script_name.py"; it doesn't work. Yet, when I run it using "Python script_name.py", everything works.


回答1:


From cron you should be running the script as script_name.py and your script meets the following criteria:

  • Executable bit is set
  • The script's hash-bang is set correctly eg. #!/usr/bin/env python
  • it is accessible from the PATH
    • e.g. place it in /usr/local/bin/ or /opt/local/bin/ (and they are accessible to your system PATH.)

If these conditions are met, you should be able to run it from anywhere on your local system as script_name.py



来源:https://stackoverflow.com/questions/4486472/running-a-python-script-using-cron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!