#!/bin/bash

ADMIN="your_email@gmail.com"
SMTP="smtp.gmail.com:587"
FROM="Alert@gmail.com"
NEW="Files"

which sendEmail > /dev/null
MISSING_SENDEMAIL=$?
if [ $MISSING_SENDEMAIL -eq 1 ]; then
   echo "sendEmail is required. Get it here:http://caspian.dotconf.net/menu/Software/SendEmail/"
exit 1
fi

touch /home/<user>/.config/current_ip

wget -qO - http://cfaj.freeshell.org/ipaddr.cgi > /home/<user>/.config/new_ip
DIFFER=$( diff -aq /home/<user>/.config/new_ip /home/<user>/.config/current_ip | cut -s -d' ' -f1 )

if [ "$DIFFER" = "$NEW" ] ; then
   sendEmail -s $SMTP -f $FROM -t $ADMIN -u "New IP address for $(hostname)" -o message-file=/home/<user>/.config/new_ip -xu your_smtp_user -xp your_smtp_password
   mv /home/<user>/.config/new_ip /home/<user>/.config/current_ip
fi

