简体   繁体   English

为什么在我的情况下,带有“终端通知程序”的 Python 脚本不能与 crontab 一起使用?

[英]Why Python script with “terminal-notifier” isn't working with crontab in my case?

I'm using macOS (Catalina).我正在使用 macOS (Catalina)。

Just wrote a little Python script which makes GET request to website, search for the specific value and then show it via 'terminal-notifier' application.刚刚写了一个小 Python 脚本,它向网站发出 GET 请求,搜索特定值,然后通过“终端通知程序”应用程序显示它。

It works fine through terminal, but when I use crone — nothing is happening.它通过终端工作正常,但是当我使用 crone 时 - 什么也没有发生。

I tried almoust everything:我几乎尝试了一切:

* * * * * export DISPLAY=:0.0 && cd /Users/ayztuva/Dev/Scripts/Python && ./usd.py

* * * * * export DISPLAY=:0 && cd /Users/ayztuva/Dev/Scripts/Python && ./usd.py

* * * * * export DISPLAY=:0.0 && /usr/local/bin/Python3 /Users/ayztuva/Dev/Scripts/Python/usd.py

* * * * * /usr/local/bin/Python3 /Users/ayztuva/Dev/Scripts/Python/usd.py

but no progress.但没有进展。

Can't figure out what's wrong.无法弄清楚出了什么问题。 Am I missing something?我错过了什么吗?

I found where was the problem — in cron environment we have empty PATH variable (at least on macOS).我发现问题出在哪里——在 cron 环境中,我们有空的 PATH 变量(至少在 macOS 上)。 So I assume there just no way to execute all my includes in script (please correct me if I'm wrong).所以我认为没有办法在脚本中执行我所有的包含(如果我错了,请纠正我)。

So here is a working example:所以这是一个工作示例:

# ┌─────────────────────  Minute   (0..59)
# │ ┌───────────────────  Hour     (0..23)
# │ │ ┌─────────────────  Day      (1..31)
# │ │ │ ┌───────────────  Month    (1..12)
# │ │ │ │ ┌─────────────  Weekday  (0=Sun .. 6=Sat)
# ┴ ┴ ┴ ┴ ┴
# * * * * *
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
0 23 * * * /usr/local/bin/Python3.8 /Users/ayztuva/Dev/Scripts/Python/usd.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM