So I have tried basically every single cron related google search result all to no avail. this is the script:
#!/bin/bash
todaysDateNumber=$(date '+%j')
sloc="$(dirname "$(readlink -f $0)")"
if ! grep "busy" "$sloc/$1prog_state.txt"; then
echo "busy" >> "$sloc/$1prog_state.txt"
wget "https://twitchtracker.com/$1" -O "$sloc/$1streamer.html"
if grep 'LIVE</span>' "$sloc/$1streamer.html"; then
doesExist=$(cat "$sloc/$1stream_state.txt" | grep -i -m 1 "$todaysDateNumber")
if [ -z "${doesExist}" ]; then
echo "stream found"
if [ "$(notify-send "$1 is online!" "https://www.twitch.tv/$1/" -u CRITICAL -a "$1-detector" -A 'Open Stream' -A 'Nope')" -eq '0' ]; then
xdg-open "https://www.twitch.tv/$1/"
fi
rm "$sloc/$1stream_state.txt"
echo "$todaysDateNumber" >> "$sloc/$1stream_state.txt"
fi
else
echo "No stream, exiting."
fi
rm "$sloc/$1streamer.html"
fi
rm "$sloc/$1prog_state.txt"
this it what SHOULD be happening (only behaves properly when run through a terminal window)
cron doesnāt know anything about the display manager. You can try prefixing the command with DISPLAY=:0 and see if that helps, or possibly in the bash script itself, you could try setting the DISPLAY value to :0 and see if that helps.
Iāve long said that computers do exactly what you tell them to. The trick to getting them to do what you want is to make sure that what you told it to do is what you wanted it to do. Often times, thatās where the issue is.
In the case of cron, itās intended to run background tasks, and it runs the tasks in that environment - not in the desktop environment. If another user is logged in, this probably wouldnāt work, because they wouldnāt be authorized to access the display.
BTW, display :0 is usually the default - :1 is usually a second display (not necessarily a second monitor, but a second Xorg instance).
If it were me, Iād probably look to see if there was an event-driven way to do it rather than a polling way to do it.
Itās likely there is some sort of a ātwitch indicatorā open source application that might have some ideas about how to do this with the twitch API rather than scraping an HTML page (which can prove very frustrating as things are updated on the page).
If the goal is to learn while doing it, thatās one thing - if you just want a solution, thatās something else.
mostly just trying to learn, but also need the functinality. primarily for my brother since the streamer i tune into while I am doing things goes on at the same time every as opposed to this discord meme person that he likes watching.
So you would create a systemd service eg 40476.service for your script, then call the timer name the same eg 40476.timer and save both in ~/.config/systemd/user/ and as your user run systemctl --user enable --now 40476.timer
for the sake of me learning, (I have only been on linux for about 1.7 years) could you explain how the values work?
because it looks like it is running every 5 minutes
this was the one I made from pulling together stuff off google
[Unit]
Description=Run every 15 minutes from 10:30 AM to 8:30 PM
[Timer]
OnCalendar=*-*-* 10-20:30/15
[Install]
WantedBy=timers.target
Then there is systemd-analyze calendar your string for example;
systemd-analyze calendar "*-*-* 10:30,20:30/15"
Original form: *-*-* 10:30,20:30/15
Normalized form: *-*-* 10:20,30:30/15
Next elapse: Thu 2024-05-16 10:20:30 CDT
(in UTC): Thu 2024-05-16 15:20:30 UTC
From now: 13h left