user487588
user487588

Reputation: 740

Cron Syntax, MAC OS X

Quick Summary of Issue

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?

More Detailed Explanation

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

Answers (3)

khachik
khachik

Reputation: 28703

... (cd ~/desktop/WebProgramming/ && python ...)

Upvotes: 1

Nev Stokes
Nev Stokes

Reputation: 9799

Try and specify absolute paths to scripts when using cron

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

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

Related Questions