简体   繁体   中英

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

I'm using 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.

It works fine through terminal, but when I use crone — nothing is happening.

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). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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