Forked from scottlee/Get external IP, write to file
Last active
October 20, 2018 20:41
-
-
Save RajatNair/54ea47c165e3db2e49718313c8a6dc0f to your computer and use it in GitHub Desktop.
Get external IP address and write to file if it has changed
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 | |
# Where should this file be stored? | |
ipfile=~/Desktop/external-ip.txt | |
# Go ahead now, go ahead and get that IP | |
IP=$(curl -s https://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