Created
August 12, 2011 20:31
-
-
Save scottlee/1142927 to your computer and use it in GitHub Desktop.
Get external IP address and write to file if it has changed
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/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