Created
June 17, 2013 18:17
-
-
Save afragen/5798962 to your computer and use it in GitHub Desktop.
I run this script using an ssh key to create a file with the current IP of my machine. Change user@host.com to a user with ssh key pair on your machine. I then access this file from my 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
#!/usr/bin/env bash | |
# This script should only generate an email when the WAN IP has changed. | |
# run in launchd | |
#test for any parameter, true if debugging | |
test -n "$1" && dbg=$1 || dbg=false #;dbg=true | |
echo "Running $0" | |
my_ip=`curl -s http://checkip.dyndns.org | awk '{print $6}' | awk ' BEGIN { FS = "<" } { print $1 } '` | |
if [[ -s /tmp/prevIP.txt ]]; then | |
prevIP=$(cat /tmp/prevIP.txt) | |
else | |
echo "initialize" > /tmp/prevIP.txt | |
prevIP=$(cat /tmp/prevIP.txt) | |
fi | |
if [[ $my_ip != $prevIP ]]; then | |
echo $my_ip > /tmp/prevIP.txt | |
my_change=`echo $prevIP "-->" $my_ip` | |
echo $my_change | |
scp /tmp/prevIP.txt user@host.com:/tmp | |
fi | |
t=`date +%k` | |
t=`expr $t % 4` | |
if [[ $t = 0 ]]; then | |
echo "sending current IP" | |
scp /tmp/prevIP.txt user@host.com:/tmp | |
fi | |
if [[ $debug == true ]]; then | |
echo "====" | |
echo `cat /tmp/prevIP.txt` | |
echo $t | |
echo "====" | |
rm /tmp/prevIP.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment