Skip to content

Instantly share code, notes, and snippets.

@jotson
Last active November 5, 2025 23:59
Show Gist options
  • Select an option

  • Save jotson/a46cb412704aa8852ae70535201565e3 to your computer and use it in GitHub Desktop.

Select an option

Save jotson/a46cb412704aa8852ae70535201565e3 to your computer and use it in GitHub Desktop.
bash script that uses the twitch CLI to scan for a specific game being streamed
#!/bin/bash
# Monitor twitch streams for specific games and alert when someone is playing
# Get game_id: twitch api get games -q name="The Mailroom"
# You can pass in multiple game_ids by adding the game_id param multiple times
# Twitch CLI https://dev.twitch.tv/docs/cli/
# The Mailroom = 1216417455
LOG="log.txt"
echo "Waiting for live streams..."
while true; do
OUTPUT=$(twitch api get streams -q game_id=1216417455 2>&1)
if [[ "$OUTPUT" == *token* ]]; then
echo "Refreshing token"
twitch token refresh
sleep 3
continue
fi
DATA=$(echo $OUTPUT | jq '.data | length')
if [[ "$DATA" != "0" ]]; then
TITLE=$(echo $OUTPUT | jq -r '.data[0].title')
LOGIN=$(echo $OUTPUT | jq -r '.data[0].user_login')
URL="https://twitch.tv/$LOGIN"
MESSAGE="Twitch Live Stream $LOGIN: $TITLE"
LOGMESSAGE="$(date --iso-8601) @$LOGIN $URL"
grep "$LOGMESSAGE" "$LOG" >/dev/null
if [ $? -ne 0 ]; then
echo "$MESSAGE"
echo "$LOGMESSAGE" >>"$LOG"
fi
fi
sleep 120
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment