Last active
April 8, 2019 17:19
-
-
Save spitfire05/53e76ee90aaaeb24bb5411f794be2f20 to your computer and use it in GitHub Desktop.
A shell script checking the public IP of the host it is run on, and uploading to to a git repository
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
print_usage () { | |
echo "USAGE: updateip.sh PATH FILE" | |
} | |
if [ -z "$1" ]; then | |
print_usage | |
exit 1 | |
fi | |
if [ -z "$2" ]; then | |
print_usage | |
exit 1 | |
fi | |
cwd="$(pwd)" | |
cd $1 | |
git pull --force | |
ip="$(dig +short myip.opendns.com @resolver1.opendns.com)" | |
echo "$ip" > $2 | |
diff="$(git diff)" | |
if [ -n "$diff" ]; then | |
git add $2 --force | |
git commit -m "$ip" | |
git push --force | |
fi | |
cd "$cwd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment