Last active
May 17, 2021 13:22
-
-
Save gerlof85/ed4f3450883e69191492f57ddfa6dd65 to your computer and use it in GitHub Desktop.
updated twodns updater, which only calls the API if current external ip is different from the one stored in current_ip.txt
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 | |
path="/usr/local/bin/twodns/" | |
# create file if it doesn't exist | |
if ! test -f $path"current_ip.txt"; then | |
echo "empty" > $path"current_ip.txt" | |
fi | |
ip_address=`cat /usr/local/bin/twodns/current_ip.txt` | |
my_ext_ip=$(curl -sS http://ipv4.icanhazip.com) | |
log=$path"ddns_updater.log.txt" | |
# echo "n$(date -u) IP in file " $ip_address " external IP " $my_ext_ip >> $log | |
if [ $ip_address = $my_ext_ip ] | |
then | |
echo "\n$(date) ip adresses are equal, not updating" >> $log | |
else | |
# update ip in file and online | |
echo "$my_ext_ip" > $path"current_ip.txt" | |
echo "\n\n\n===== \ | |
\n$(date) \ | |
\nUpdating IP to: $my_ext_ip \n" >> $log | |
curl -isSX PUT \ | |
-u "[email protected]:YOUR_API_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
--data '{"ip_address":"'$my_ext_ip'", "activate_wildcard": "false"}' \ | |
https://api.twodns.de/hosts/YOUR_HOSTNAME.dynvpn.de >> $log | |
exit | |
fi |
- added path reference for improved file/log handling. Note: the path needs to be updated in 2 lines in case the script is used in a different location (this needs to be improved)
- remove -u after date calls to make log timestamps in sync with current timezone
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this script is based on https://gist.github.com/oliveratgithub/a50a3d6bcb1e030ed06e
changes