Created
July 21, 2017 19:17
-
-
Save cbuelo/7c9d049b6bb473f2ae3e02ec2f148899 to your computer and use it in GitHub Desktop.
Script for getting local computer's current IP address and writing it to remote server
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 | |
# this script and "currentIP.txt" must be in the same directory | |
# run "(hostname -I) > currentIP.txt" in bash before running this script the first time | |
ip_rightNow=$(hostname -I) | |
ip_prev=$(cat currentIP.txt) | |
if [[ "$ip_rightNow" != "$ip_prev" ]]; then | |
echo $ip_rightNow > currentIP.txt | |
scp currentIP.txt [email protected]:/path/to/directory | |
fi | |
# above depends on ssh key authentication (no passphrase on key) | |
# can add this to crontab to run every Y minutes with: | |
# */Y * * * * /path/to/updateIP.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment