The provided instructions are related to managing multiple targets in the DynDNS service using Cron jobs. Here's a step-by-step guide on how to address each instruction:
1. **Send NOTHING message if "STATUS:NO_CHANGE":**
- To follow these instructions, you can write a simple script that checks for the status:
echo $? ; sleep 2 and then send nothing with a condition where only the second line
sleep 2; echo "" ; exit; will terminate the script. This way, depending on the result, you'll decide whether to send NOTHING or further action.
- Example:
``
bash
#!/bin/bash
# Wait for status: "STATUS:NO_CHANGE" in DynDNS
while true; do
echo $? ; sleep 2 >> /dev/null
done <<< "$(curl -s -i 'http://api.dyndns.org/dyncmd/dnsping?name=&type=udp' 2>&1)"
# If it's "STATUS:NO_CHANGE", send NOTHING
if [ $REPLY -ne 0 ]; then
echo "NO_REPLY" > /dev/null
fi
# The script exits with code after the 'exit;'.
`
2. **Send update messages for successful updates but NO REPLY with non-zero exit code:**
- To achieve this:
`
bash
#!/bin/bash
while true; do
echo $? ; sleep 2 >> /dev/null
done <<< "$(curl -s -i 'http://api.dynfds.org/dyncmd/dnsping?name=&type=udp')"
# Initialize variables to keep track of whether an update was sent for a specific event or no change
var_success=0; var_nochange=false
read -p "Update (Y/N)? ";
if [ "$1" == "y" ]; then
echo "+ $REPLY" > /dev/null # send success message for Update
if [ $var_success- ne 0 ] ; then
# Set var_success to True, update is sent
var_success = ($var_success +1)
fi
else
echo "- ";
read -p "No change (N)? ";
if [ "$1" == "y" ]; then
// If no_change is TRUE, send NOTHING; set var_nochange True and continue.
# set variables
var_nochange=true;
# No update code here. Use this for any non-zero exit.
echo "+ $$ ; sleep 5" >> /dev/null
else
echo "- $REPLY" >> /dev/null
fi
`
3. **Send messages to specific targets when DynDNS updates:**
- To make sure to send the correct messages for each target, you can use environment variables:
`
bash
#!/bin/bash
var_update=false
while true; do
echo $? ; sleep 2 >> /dev/null
if [ "$REPLY" == "20" ] && [ $var_update == false ]; then
update_command=" 'your update_message_here'; "
echo "UPDATE: ", " ", "$(curl -s -i '//api updates' 2>&1' | cut -d "=" -f7)" >> /dev/null;
# Send everything to first target
exit;
fi
if [ $var_update ==true ]; then
var_update false
echo "NO CHANGE"
# If it's NO_CHANGE, send NOTHING with a 0 exit code,
# otherwise send an update.
`
Here is an example for sending the first message in any DynDNS event: update_command=" 'your update_message_here';"`:
4. **Never send routine "no change" notices:**