To handle the specified task, you'll need to write two separate scripts:
**1. Output correction script**
This script will check for and repair any errors encountered during the dynDNS update process by running a cron job at a scheduled time using the provided
/root/.hermes/skills/cf-dyndns.sh command.
``
bash
# Schedule to run daily in the background at 3am
*/1 * * * * /root/.hermes/skills/cf-dyndns.sh 2>&1
`
**2. Sending updated message if there is any change or error**
Create a script that checks for updates like this:
`
bash
#!/bin/bash
# Check the DynDNS status using cron job from earlier
output=$(curl -s "https://api.dyn.com/v12/status")
if [ $? -ne 0 ]; then
# Send update messages based on dynDNS update result
if [ "$output" == "STATUS:NO_CHANGE" ]; then
echo "NO_REPLY"
elif [ "$output" == "SUCCESS:OK" ] || [ "$output" == "SUCCESS:*" ] || ([ $(( $(echo "$output" | cut -d ' ' -f1) > 0 ) && \( ( $(echo $output | sed -n '\;p' | tr '\n' ' ' | tr '[:alnum:][:space:]' '\01' ) <= 50000 ) ); echo "dynDNS updated ($((( $(echo "$output" | cut -d ' ' -f1) > 0 ) && \( ( $(echo $output | sed -n '\;p' | tr '$' '\?' ) <= 40000 ) || \( ( $(echo "$output" | cut -d '-' -f2- | tr ':' '-/ ' ) == '--max-codeset' ) ); echo '');"
elif [ "$output" == "ERROR"; then
echo "ERROR"
fi
else
# Send update messages based on dynDNS error result
echo "ERROR \"$output\""
fi
fi
# Update the message subject to reflect the output status to sender of DynDNS and telegram private channels
echo "%[error: $0]" | xdotool send -d --sync-mouse 1 --scroll-up --sync-key ctrl+a --sync-select-window 3 --send-action "updateMessage "
`
This script checks the dynDNS update result via cron job at a scheduled time. If it's an error or nochange status, it sends an update message to all three channels: Telegram private channel with id -1003980922525
, Discord private channel with ID 1511697499654459422
, and this own DM (with its given id) by sending the corresponding updateMessage
command using the -D
argument. This is a fallback for failure in case of external dynDNS updates, for example. The subject of this update message will be filled out by calling xdotool
with these lines.
After creating the scripts, run them every day to receive the status and any failed or unchanged updates via notifications:
* Send nothing (no reply) when "NOCHANGE" error is encountered because there's no error response from dynDNS API. The notification will only contain NO_REPLY.
* Print a warning message along with error details (or a non-zero exit code) for each successful update.
* Send an error notification when nochange or success with codeset changes (--max-codeset
, --success:OK
or --success:*`) are met.