Skip to content

Instantly share code, notes, and snippets.

@theKAKAN
Last active May 23, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theKAKAN/d70feb19fe10a3121812a538eeabf4e2 to your computer and use it in GitHub Desktop.
Save theKAKAN/d70feb19fe10a3121812a538eeabf4e2 to your computer and use it in GitHub Desktop.
Checks for MQTT subbed-topic in Termux or linux and sends push notifications on receiving a message
#!/usr/bin/env bash
IP="10.0.0.1" #Change to IP of server
TOPIC="torrent/finished" # Change to your liking
VERSION="mqttv5"
if [ -n "$(command -v mosquitto_sub)" ]; then
echo "Found mosquitto"
if [ "$( uname )" == "Linux" ]; then
if [ -n "$( command -v termux-notification )" ]; then
echo "Running in termux"
mosquitto_sub -h "$IP" -V "$VERSION" -t "$TOPIC" | while read OUTPUT; do termux-notification -c "$OUTPUT"; done
elif [ -n "$( command -v notify-send )" ]; then
echo "Using notify-send"
mosquitto_sub -h "$IP" -V "$VERSION" -t "$TOPIC" | while read OUTPUT; do notify-send "$TOPIC" "$OUTPUT"; done
else
echo "Install a compatible notification service."
fi
else
echo "You must run a compatible OS"
fi
else
echo "Mosquitto not found"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment