Created
November 20, 2011 01:45
-
-
Save c00kiemon5ter/1379684 to your computer and use it in GitHub Desktop.
update your dynamic IP, for freedns.afraid.org; place under cron
This file contains hidden or 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 | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace
updateurl
with yours and place under/etc/cron.hourly