#!/bin/sh # # CopyLeft moon.cat # This work is licensed under a Creative Commons Attribution 4.0 International License. # # Author: Rei Izumi - moon.cat - blog.moon.cat - 2017 # # IP_FILE='/scripts/IP.txt' MAIL_TO=tu_email@domain.cat #Name of the user sending the mail MAIL_SENDER='Request IP ' MAIL_SUBJECT='New IP: ' #Check old IP if [ -f "$IP_FILE" ]; then oldIP=`cat $IP_FILE` else oldIP= fi #Retrieve actual IP newIP=`wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d':' -f 2 | cut -d' ' -f 2 | cut -d'<' -f 1` echo "Old IP: $oldIP" echo "New IP: $newIP" if [ "$newIP" != "$oldIP" ]; then printf "Old IP: $oldIP\nNew IP: $newIP" | mail -s "$MAIL_SUBJECT$newIP" -r "$MAIL_SENDER" $MAIL_TO echo $newIP > $IP_FILE fi