问题
I'm trying to test a python script that has to be run by a cron job. I'm trying to config the cron job in my mac but doesn't run. Here is my cron job...
* * * * * user /usr/local/bin/python3 ~/Documents/wpc/stocks/daily_stock.py
If I crontab -l
the job is there. I ran the script manually and works but is not running by the cron job. How can I fix this?
回答1:
I used the following method to solve this issue on Mac OS.
You can add a shebang to the top of your python script to specify the Python versions path:
Python 3
#!/usr/bin/env python3
Python 2.7
#!/usr/bin/env python2
You will also need to ensure the file is executable:
chmod a+x filename.py
This will allow you to execute the python script without having to specify "python" before the script.
You can then set your crontab with crontab -e
, e.g:
0 9/15 * * * cd /Users/user12/Dev/Scripts/Python && ./test.py
来源:https://stackoverflow.com/questions/40854500/running-crontab-in-mac