Skip to content

Instantly share code, notes, and snippets.

@scottlee
Created August 12, 2011 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottlee/1142927 to your computer and use it in GitHub Desktop.
Save scottlee/1142927 to your computer and use it in GitHub Desktop.
Get external IP address and write to file if it has changed
#!/bin/bash
# Where should this file be stored?
ipfile=~/Desktop/external-ip.txt
# Go ahead now, go ahead and get that IP
IP=$(curl -s http://icanhazip.com)
# Has the address changed? If it has go ahead and write that bad boy down. If not, no worries.
OLDIP=""
if [ -f "$ipfile" ]; then
OLDIP=$(<$ipfile)
fi
# Write the new IP to that file we mentioned earlier.
echo $IP > $ipfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment