To perform these actions, you will need to create a shell script named
cf-dyndns.sh that runs under the root user (
/root). Here is an example of what such a script might look like:
``
bash
#!/bin/bash
# Set the source IP and DynDNS domain from environment variables
SourceIP=$(getent Env "DYNDNS_SOURCE_IP" | cut -d= -f2-)
DynDNSDomain="your-dynnlds-domain.com"
# Fetch the current time every minute
for i in {0..59}; do
sleep 60>$i
echo "$(date +"%Y/%m/%d %H:%M:%S") > /dev/null"
done
echo "INFO: Checking DynDNS status..."
# Run a test to check if DynDNS is running, update its contents with the current time,
# and update its URL.
DynDNSTest=$(curl -s https://api.dynadns.com/api/1/tests/$SourceIP)
echo "INFO: Update contents of $DynDNSDomain."
# Use http:// to fetch an updated version of the dynnlds-domain
http://$DynDNSDomain/update?status=update&source_ip=$SourceIP
echo "WARNING: There was an error testing DynDNS!"
# If there's a problem with DynDNS, send a notification:
if [ $? -ne 0 ]; then
echo "WARNING: DynDNS ERROR - $?"
# Send messages to all three target channels.
for Tgt in "-1003980922525" "1511697499654459422" "1812605657";
do
echo ".INFOTEXT\nDynDNS Error: [error output found."
if ! echo "ERROR: The DynDNS tests have failed. Please contact us at $Tgt to assist.\n"; > /dev/null; then
echo ".WARNING: It looks like the DynDNS issue was fixed, however we still want you aware of this bug so that anyone else experiencing issues may know to run a 'check-dynns.sh script to verify your setup."
fi
done
done
# Send an update message to all three target channels.
for Tgt in "-1003980922525" "1511697499654459422" "1812605657"; do
if ! echo ".INFOTEXT\nThe updates have been applied. Please verify your DynDNS settings correctly.\n"; >> /dev/null; then
echo ".WARNING: An update has occurred, but it may not affect everyone - check the DynDNS documentation to confirm how you should proceed in this scenario."
fi
done
for Tgt in "-1003980922525" "1511697499654459422" "1812605657"; do
echo ".WARNING: We have confirmed that there has been no error, however we still want your awareness of the issue so that users across different servers may experience connectivity issues or unresponsiveness."
done
else
echo "INFO: Test DynDNS completed successfully!"
fi
`
You can now save this script and make it run every minute when it's scheduled by crontab. It looks for Dyn-
prefix followed by a domain name in all files named check-dynns.sh
.
**For example you will need to add the following:**
`
bash
* * * 0-59 /root/check-dynns.sh
`
Please replace "your-dynnlds-domain.com"
with your dynamic DNS domain.
The script checks for the presence of a DynDNS test result, if not present it appends TEST
and requests it from DynDNS. It also handles the case where dynDNS encounters an error at some point during this process and sends notifications as required by you when necessary.
Remember that this example uses HTTP ()" target="_blank" rel="noopener">http://) to fetch new versions of your DynDNS domain. If there are any issues with receiving these updates, like a network outage or incorrect credentials, you may need additional checks.
Please test and verify the actions for
check-dynnls.sh once it runs in production before including it into your scripts in place that require it to be executed.