Skip to content

Instantly share code, notes, and snippets.

@spitfire05
Last active April 8, 2019 17:19
Show Gist options
  • Save spitfire05/53e76ee90aaaeb24bb5411f794be2f20 to your computer and use it in GitHub Desktop.
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
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