Last active
November 4, 2021 17:33
-
-
Save ibressler/53ea52c88392831b615d65091281dc38 to your computer and use it in GitHub Desktop.
ddnss update script
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 | |
# derived from https://www.ddnss.de/info.php | |
# To be stored in /etc/dhcp/dhclient-exit-hooks.d/99_ddnss_update | |
# Updates the specified subdomain $HOSTNAME with the current IP address. | |
UPDATE_KEY="<your update key displayed in the dashboard" | |
HOSTNAME="*.ddnss.*" | |
DDNSS_PATH="/var/run/ddnss" | |
ALLHOST="" # 'all' for updating all hosts in the account | |
TS="$(date +%Y-%m-%d\ %H:%M:%S)" | |
IP="$(curl -s www.ddnss.de/jsonip.php | jq -r '.IP')" | |
OLDIP="$([ -f "$DDNSS_PATH/oldip.txt" ] && cat "$DDNSS_PATH/oldip.txt")" | |
mkdir -p "$DDNSS_PATH" | |
echo "Current IP: $OLDIP" | |
if [ x"$IP"x = x"$OLDIP"x ]; then | |
echo "$TS - Same IP - NOT UPDATING" >> $DDNSS_PATH/log.txt | |
else | |
echo "$TS - New IP: $IP / Old IP: $OLDIP - UPDATING!" >> $DDNSS_PATH/log.txt | |
echo $IP > $DDNSS_PATH/oldip.txt | |
URL="https://www.ddnss.de/upd.php?key=$UPDATE_KEY&host=$HOSTNAME" | |
[ -z "$ALLHOST" ] || URL="$URL&host=$ALLHOST" | |
curl -s "$URL" >> $DDNSS_PATH/log.txt | |
echo " " >> $DDNSS_PATH/log.txt | |
echo "Updating ..." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment