Skip to content

Instantly share code, notes, and snippets.

@steverobbins
Last active December 21, 2015 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverobbins/a696bc0156b86da34f8d to your computer and use it in GitHub Desktop.
Save steverobbins/a696bc0156b86da34f8d to your computer and use it in GitHub Desktop.
Cron script I leave running on my home computer in case my ISP decides to change my IP
#!/bin/bash
BIN_CURL=$(which curl)
FILE_IP=/Users/steve/Dropbox/ip-home
URL_DETECT=icanhazip.com
echo "Config values:
curl bin: $BIN_CURL
ip file: $FILE_IP
detection url: $URL_DETECT
"
IP_OLD=$(cat "$FILE_IP")
echo "Current IP: $IP_OLD"
IP_NEW=$($BIN_CURL -sS "$URL_DETECT" 2>/dev/null)
echo "Detected IP: $IP_NEW"
if [ ! -z "$IP_NEW" ] && [ "$IP_NEW" != "$IP_OLD" ]; then
echo "Updating..."
echo "$IP_NEW" > "$FILE_IP"
else
echo "Detected IP was empty or unchanged"
fi
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment