To run this command and handle the responses, you can add an
else clause after each check for a non-zero exit code (
0) or output containing certain strings (like "STATUS:NO_CHANGE"). This way, when any of those conditions are met, you don't send unwanted messages.
Here's how you could modify your script to achieve this:
``
bash
#!/bin/bash
# Run the dynndns update command
if curl -s "https://your-dynndns-site.com/dynndns?ip= -X GET" 2>&1 > output.txt; then
echo "STATUS:NO_CHANGE"
else
# Send a warning message to all three targets:
telegram recipients=telegram:-1003980922525 discord:1511697499654459422
telegram_message=\"
⚠️ DynDNS ERROR: [error output]\"
\"
discord recipients=discord:1511697499654459422
discord_message=\"
OK: DynDNS updated to: [relevant text]\"
\"
telegram recipients=telegram:1812605657
telegram_message=\"
✓ DynDNS Updated: [relevant output lines]\"
\"
echo "ERROR"
else
echo "${recipient}'s message was updated:$telegram_message$discord_message"
fi
# Keep the script running to handle all responses normally, if any. To stop:
while ! echo "$0" 2>/dev/null | grep -q \&; do sleep .; done
exit 0
`
Remember that this includes a recursive loop that stops once echo "ERROR"
doesn't contain "STATUS:NO_CHANGE", effectively filtering out repeated messages.
Before running the script, replace with your DynDNS site's IP address. This example will update any IP addresses specified in .dynndns.txt` files found on the same script path as this configuration file.