Created
December 18, 2015 06:13
-
-
Save philpennock/c358010a678bed412f30 to your computer and use it in GitHub Desktop.
7 * * * * /usr/local/sbin/update-home-ip cron
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/bash -eu | |
progname="$(basename "$0")" | |
die() { printf >&2 "%s: %s\n" "$progname" "$*" ; exit 1; } | |
if [[ $# -gt 0 && "$1" == "cron" ]]; then | |
sleep $((10 + RANDOM % 40 )) | |
fi | |
dynhost=CENSORED | |
dynpass='CENSORED' | |
myip=$(curl -sS 'https://www.icanhazip.com/') | |
if [[ ! "${myip:?}" =~ ^[0-9.]+$ ]]; then | |
die "IP derivation did not give an IP address" "$myip" | |
fi | |
# curl -k is insecure, but it's a self-signed cert, just get protection against | |
# sniffing, not active attacks | |
set +e | |
result="$( | |
curl -k -sS --basic -u "${dynhost:?}:${dynpass:?}" \ | |
"https://dyn.dns.he.net/nic/update?system=dyndns&hostname=${dynhost:?}&myip=${myip:?}" | |
)" | |
retval=$? | |
case $retval in | |
0) priority=daemon.info ;; | |
*) priority=daemon.err ;; | |
esac | |
logger -p $priority "$progname update of ${dynhost:-?} to ${myip:-?} exited $retval and yielded: $result" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment