#!/bin/bash

# file to save the last recorded ip
LASTIPFILE=/tmp/lastip
# file to save an ip-history
LOGFILE=/home/username/ip.log

# if lastipfile does not exist, create it
if [ ! -e $LASTIPFILE ]; then
  echo "NoIpSavedYet" > $LASTIPFILE
fi 

# get the current ip with a script from www.gimme-th.at
IP=`./checkip.sh`
# Get the last ip
LASTIP=`cat $LASTIPFILE`

# uncomment for debugging
#echo "IP ist $IP"
#echo "LASTIP ist $LASTIP"

if [ $IP != $LASTIP ]; then
  # output message
  echo "IP geaendert, neue IP ist $IP";
  # append ip to logfile
  echo `/bin/date +%Y%m%d_%H%M%S` $IP >> $LOGFILE 
  # remember current ip until next check
  echo $IP > $LASTIPFILE 
fi


