Last active
December 21, 2015 03:50
-
-
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
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 | |
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