Search code examples
python-3.xcronmacos-catalina

How do I schedule a python script using cron on OS X Catalina


So i'm trying to setup a cron job in Mac OS X Catalina 10.15.3. For some reason I can get my python script running. I setup a test job under it and that one works perfectly.

* * * * * python3 /Users/eric/Dropbox/python/Print/New\ Orders/funcs.py
* * * * * echo 'hello' >> //Users/eric/Desktop/test/test.txt
``

the echo is running every minute but for some reason I cant the the python file to run.

Solution

  • The safest option is the put the full path to the script. For your specific case you can find it by executing which python3.
    In alternative, you can add the PATH definition into your crontab, e.g.,

    PATH=$PATH:/usr/local/bin:/Users/abc/path/to/python
    

    Also, you could redirect the stdout and stderr to some file to have a clearer view of what's going on

    * * * * * python3 /Users/eric/Dropbox/python/Print/New\ Orders/funcs.py 1>/tmp/stdout.log 2>/tmp/stderr.log