Skip to content

Instantly share code, notes, and snippets.

@cbuelo
Created July 21, 2017 19:17
Show Gist options
  • Save cbuelo/7c9d049b6bb473f2ae3e02ec2f148899 to your computer and use it in GitHub Desktop.
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
#!/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