如何在OS X Catalina上使用cron计划python脚本 [英] How do I schedule a python script using cron on OS X Catalina
问题描述
所以我试图在Mac OS X Catalina 10.15.3中设置cron作业。由于某种原因,我可以运行我的python脚本。我在其下设置了一个测试作业,并且该作业完美运行。
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.
推荐答案
最安全的选择是将完整路径放入脚本。对于您的特定情况,您可以通过执行 which python3
找到它。
或者,您可以将PATH定义添加到您的crontab中,例如,
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
此外,您可以将stdout和stderr重定向到某个文件,以更清楚地了解正在发生的事情
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
这篇关于如何在OS X Catalina上使用cron计划python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!