script that send mail whwm Ip cahnge

Hello
I want to write a script that will run every 1 hours and check the IP I get and send me an E-mail if it’s change.
this is what I wrote so fat
my problem is how to save the old ip \where to put him


:global newip [/ip address get [find interface=ppp-out1] address];
:log warning "New IP is-$newip";

:if ($oldip !=$newip) do={:log warning "IP change to-$newip";
/system script run mail;
:global oldip=$newip; } else={:log warning "IP didn't change";:global oldip=$newip; };

:log warning "******script finish******";

thanks ,

Easiest place is in a comment field. In my experience, the best place is on the interface the DHCP server is running on (/interface etherX set comment=“1.2.3.4”) - that way it survives reboots and power cuts.

try this



{
:global oldip;
:local newip [/ip address get [find interface=ppp-out1] address];
:log warning "New IP is-$newip";
:if ($oldip !=$newip) do={:log warning "IP change to-$newip";
/system script run mail; set oldip $newip} else={:log warning "IP didn't change"; };
:log warning "******script finish******";
}

this is good option
I did something else - I wrote the value into a file and then read\write to him.
but I’ll try it also
Thanks !

1 more thing -
maybe you know how I can cancel the subnet of the ip

I get 91.152.24.87/32
I want to get only the 91.152.24.87
that way I can send the ip as a link

?

thanks ,

like this

{
:local ip [/ip address get [/ip address find interface="wan"] address]
:local currentIP [:pick $ip 0 [:find $ip "/"]]
put $currentIP
}

Thank you!

1 more question -
how can I see the IP as a link? so the person will press it and go directly to the IP
in the E-mail I see this as a text - and not as a link

{
:local ip [/ip address get [/ip address find interface="wan"] address]
:local currentIP [:pick $ip 0 [:find $ip "/"]]
put "http://$currentIP"
}

Thanks !

(again)