Reputation: 740
I would to run a python script every minute of everyday. I would like cron to run the following 2 commands (in this order) every minute:
cd ~/desktop/WebProgramming
python MyPythonScript.py
Is it possible for cron to run 2 commands?
I am having difficulty running a python script in the cron scheduler for mac. Essentially, I would like to run the script every minute, here is my Cron syntax:
* * * * * python ~/desktop/WebProgramming/MyPythonFile.py
MyPythonFile uses severals of the files in the WebProgrammingFolder--when I first navigate to the directory (cd ~/desktop/WebProgramming/
) and manually run the script, the program runs fine. However, I get an error when I try to run it on cron, saying that "No File is In the Directory" referring to the code within MyPythonFile that refers to the other files in the folder. Therefore, I would like cron to navigate to this directory, and then execute the command the run the file.
Upvotes: 1
Views: 3319
Reputation: 799082
The proper fix would be to make MyPythonFile.py
look in the appropriate directory for its files.
If you don't want to do that (...), then:
* * * * * cd ~/desktop/WebProgramming ; python MyPythonScript.py
Upvotes: 6