Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...