email when Wan IP change script

Hi All,

I’ve been playing with this script I found. (http://networkgeekstuff.com/networking/minipost-mikrotik-scripting-monitoring-interface-ip-for-changes/)

I would like to recieve an email when my wan IP changes.

 :global actualIP;
 
  :local newIP [/ip address get [find interface="ether1-Gateway"] address];
 
  :if ($newIP != $actualIP) do={
    :put "ip address $actualIP changed to $newIP";
    :set actualIP $newIP;
    /tool e-mail send to="name@gmail.com" subject="IP change detected" body=$actualIP from="MikroTik@mikrotik.com";
  }

I’ve scheduled to run this script every hour. but instead of comparing the ip addresses and mail when it changes, it keeps sending me a mail every hour.

I can’t see nothing wrong with the script.

any help would be appreciated .

delete “:set actualIP $newIP;”
and put “:global actualIP $newIP;” at the end (after /tool e-mail…)

put “:global newIP;” at the begining so you can trace the state of variables in “Environment” tab

regards