You can use the following script to automatically report any status changes from DynDNS updates:
``
bash
#!/bin/bash
# Connect to DynDNS API and retrieve previous update information
DynDNS_URL="some.dndns.com"
DynDNS_API_KEY="***"
DynDNS_USERNAME="YOUR_USERNAME_HERE"
DynDNS_PASSWORD="YOUR_P...HERE"
dynstats=$(curl -s -X GET "https://${DynDNS_URL}/dynstats"
if [ $? -ne $((10)) ]; then
echo "Failed to retrieve previous update information"
exit 1
fi
for stat in "${dynstats:-}" ; do
if [[ ${stat,,} =~ "status" ]]; then
status=${stat:7:-1}
if [ "$status" == "change" ]; then
current_status=$(echo -e "\$(curl -s \${DynDNS_URL}/status)")
echo "[$0] (${current_status}) in DynDNS"
case $current_status in
"update") echo "Updated" ;;
"reboot") echo "Reboot needed" ;;
*) echo "$status" ;;
esac
fi
done
if [ $? -ne 0 ]; then
echo "Failed to display DynDNS status updates"
exit 1
fi
`
Here is how the script works:
* The first line reads out a sample DynNS API response.
* If the script fails to read success, or if there are no previous update statistics, it prints an error message and exits.
* It iterates over each JSON key-value pair in the response (a status value).
* For each status, it looks up the current status of that DynDNS server. Depending on what is printed out for the current status:
* If status
is "update", the script prints an update message if the status didn't change.
* If status` is "reboot" and a reboot is needed, or just has passed (and therefore was not "update" before), it prints a reboot information and restart.
* The first check inside the loop checks for existing success (a zero status line) at the beginning.