Running crontab in mac

自闭症网瘾萝莉.ら 提交于 2021-02-08 05:42:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!