-
-
Save spotlesscoder/e275ed04fd617ba7b25a5099aed3baae to your computer and use it in GitHub Desktop.
Script for updating spDYN dynamic DNS entries (https://spdyn.de)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Script for updating spDYN dynamic DNS entries (https://spdyn.de) | |
# | |
# Usage: | |
# - Save this script as $HOME/bin/spDYN_update.sh | |
# - Make it executable: chmod u+x $HOME/bin/spDYN_update.sh | |
# - Create a cron entry (crontab -e) and supply <HOST_NAME> and <UPDATE_TOKEN> | |
# according to your spDYN settings. Example for running every 10 minutes: | |
# */10 * * * * $HOME/bin/spDYN_update.sh <HOST_NAME> <UPDATE_TOKEN> > /dev/null | |
# | |
# Logs are written to $HOME/.spDYN/ | |
# | |
# spDYN_update.sh, Copyright 2017 Harald Aigner <[email protected]> | |
# Licensed under the GPLv3 (https://www.gnu.org/licenses/gpl-3.0.txt) | |
if [ $# -ne 2 ] | |
then | |
echo "Usage: $0 <HOST_NAME> <UPDATE_TOKEN>" | |
fi | |
HOST_NAME=$1 | |
UPDATE_TOKEN=$2 | |
DATE=`date "+%Y-%m-%d %H:%M:%S"` | |
UPDATE_URL="https://update.spdyn.de/nic/update" | |
CHECK_IP_URL="http://checkip4.spdyn.de" | |
ip_file="${HOME}/.spDYN/${HOST_NAME}" | |
log_file="${HOME}/.spDYN/${HOST_NAME}.log" | |
old_ip="<not available>" | |
if [ -r ${ip_file} ] | |
then | |
old_ip=$(cat ${ip_file}) | |
else | |
mkdir -p "${HOME}/.spDYN" | |
fi | |
ip=$(curl -s ${CHECK_IP_URL}) | |
if [ -z "${ip}" ] | |
then | |
echo "${DATE}: error retrieving IP" | tee -a "${log_file}" | |
exit 1 | |
fi | |
if [ "${ip}" = "${old_ip}" ] | |
then | |
echo "${DATE}: no IP change (${ip})" | tee -a "${log_file}" | |
exit 0 | |
fi | |
echo "${DATE}: detected new IP: ${old_ip} -> ${ip}" | tee -a "${log_file}" | |
echo "${ip}" > "${ip_file}" | |
echo "${DATE}: wrote new IP to ${ip_file}" | tee -a "${log_file}" | |
response=$(curl -su "${HOST_NAME}:${UPDATE_TOKEN}" "${UPDATE_URL}?hostname=${HOST_NAME}&myip=${ip}") | |
echo "${DATE}: response: ${response}" | tee -a "${log_file}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment