Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created November 20, 2011 01:45
Show Gist options
  • Save c00kiemon5ter/1379684 to your computer and use it in GitHub Desktop.
Save c00kiemon5ter/1379684 to your computer and use it in GitHub Desktop.
update your dynamic IP, for freedns.afraid.org; place under cron
#!/bin/sh
cacheip="/etc/ip.cache"
checkurl='http://freedns.afraid.org/dynamic/check.php'
updateurl='http://freedns.afraid.org/dynamic/update.php?xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
[ -r "${cacheip}" ] && read -r _date _time _oldip <<< "$(tail -1 "${cacheip}")"
_newip="$(wget "$checkurl" -o /dev/null -O /dev/stdout | sed -n 's/^Detected.*: \(.\+\)/\1/p')"
[ "${_newip}" == "${_oldip}" ] && printf "IP has not changed: %s\n" "${_newip}" && exit 0
if wget -q --waitretry=5 --tries=4 "$updateurl" -o /dev/null -O /dev/stdout; then
printf "%s %s\n" "$(date +"%F %R")" "${_newip}" >> "${cacheip}"
printf "IP updated: %s\n" "${_newip}"
else
printf "%s %s\n" "$(date +"%F %R")" "failed" >> "${cacheip}"
fi
@c00kiemon5ter
Copy link
Author

replace updateurl with yours and place under /etc/cron.hourly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment