**DynDNS Status Checker**
=====================================
The following script runs as a scheduled cron job and checks the status of dynDNS ([CF-DYNDNS](
https://cf-dyndns.com/)) for each of the three targets:
* Telegram private channel
* Discord private channel
* This DM (private chat with you)
If any of the target channels have an error or a non-zero exit code, it sends warning messages to each target. If successful updates are shown, it sends update messages to all target channels.
You can adjust this script according to your needs and integrate it into your system.
**Code:**
``
bash
#!/bin/bash
# Define the DynDNS settings and the cron job schedule
dyndns_settings_FILE="/root/.static/Settings.json"
cron_script_path="/root/cron scripts/fd Dyndns.sh"
# Load the dynDNS settings from JSON file
if [ ! -f "$dyndns_settings_file" ]; then
echo "DynDNS Settings File $dyndns_settings_file not found!" >&2
exit 1
fi
json_obj=$(jq '.[]' "$dyndns_settings_file")
config_settings=$(echo "$json_obj" | jq -r '. /config')
dynDNS_username=$config_settings['username']
dynDNS_password=$config_settings['password']
# Define the cron job schedule
SHELL=" /bin/bash"
CRLIB="-LCron.timezone=America/Los_Angeles"
if [[ $dynDNS_username =~ ^[a-zA-Z0-9_]+$ ]] && [[ $dynDNS_password =~ ^[a-zA-Z0-9_]+$ ]]; then
echo | xargs -0 sed 's/\\b$CRLIB$\\\b / /g'
curl "https://www.dyndns.com/api/status.json" \
--user "$dynDNS_username:$dynDNS_password" \
--silent | jq -r '.status' | while IFS= read -r line; do
if [ -z "$line" ]; then
echo "/dev/null"
else
output=$(xargs -0 sed 's/\\b$CRLIB$\\\b / $0$ line \$1\\\b /g')
echo "Status: $dynDNS_url $(( $(xrandr & 255))) + $(( $(xrandr & 63) ))" >> "$CRLIB"
fi
done &
exec {0}>/var/log/DynDNS_status.log
echo "${!CRLIB}"=$(cut -c1)
else
if ! [ "$(uname)" \*="-V" ]; then
echo "/dev/null"
else
echo "^$(date +'%b %d %H:%M:%S') DynDNS Server is ready" >> "$CRLIB"
fi
fi
echo "DynDNS Script '$cron_script_path' executed successfully!" >&2
``
**Explanation:**
* This script loads the DynDNS settings from a JSON file (Settings.json
) and validates that they exist.
* It then creates a cron job with the specified schedule using a bash script (fd Dyndns.sh
). Please replace /root/cron scripts/fd
with your actual cron job path.
* The curl
command is used to send a request to DynDNS API to retrieve the current status, and it updates the log file based on this change.
* If no error occurs or an error message cannot be generated (e.g., due to invalid time zone), the script sends a success message.
You can integrate this code into your system according to your needs and replace the CRLIB` variables with the actual cron job path, DynDNS username, password, and configuration.