Anyone?
I've been trying to write the script myself but I ran into some problems
First this is the script I have
____________________________________________________________________________________________
:global WAN1GatewayIP
:global WAN1LastGatewayIP
#Grab current Gateway IP on WAN1
:global WAN1GatewayIP [ /ip address get [/ip address find interface="pppoe-wan1" ] network ]
:if ([:typeof $WAN1LastGatewayIP ] = nil ) do={ :global WAN1LastGatewayIP "0" }
#Check if Gateway IP has changed and apply rules
:if ($WAN1GatewayIP != $WAN1LastGatewayIP) do={
/ip route
remove [/ip route find comment=RuleWAN1-1]
remove [/ip route find comment=RuleWAN1-2]
add check-gateway=ping comment=RuleWAN1-1 distance=1 gateway=$WAN1GatewayIP%pppoe-wan1 routing-mark=to_WAN1
add check-gateway=ping comment=RuleWAN1-2 distance=1 gateway=$WAN1GatewayIP%pppoe-wan1
:global WAN1LastGatewayIP $WAN1GatewayIP
}
____________________________________________________________________________________________________________________
The idea is that I get the network ip of the interface, compare it with the previous value and if it is different then run the rest of the script in which I remove two rules (which I find having them commented) add the new ones and at the end renew the value of the LastGatewayIP so it has the latest value.
The thing is that if I run the first part of the script (#Grab current Gateway IP on WAN1) everything seems to be ok (or at least I think so, I get the variables and their respective values in the Environment tab). I added the second line (:if ([:typeof $WAN1LastGatewayIP ] = nil ) do={ :global WAN1LastGatewayIP "0" }) to make sure I get a value when I run the script for the fisrt time (remember I am not script savvy!)
When I run the whole thing (including the second part (#Check if Gateway IP has changed and apply rules)) nothing seems to happen, not even the values of the first part appear so I suppose the script breaks somewhere but I don't know where.
Notes: pppoe-WAN1 is the name of my interface and RuleWAN1-1 and RuleWAN1-2 are the comments I added on the rules I want to be able to find
Any help would be greatly appreciated