Community discussions

MikroTik App
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 19103
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Two Scripts need deciphering.

Mon Feb 22, 2021 8:15 pm

What I am trying to achieve in terms of functionality is that
when the primary ISP goes down for any reason, when it comes back up and the gateway is changed, the script will find the new gateway (from status), and implement it such
that the IP recursive routing associated starts working again.

I thought my current script was designed for that purpose but I can disable interface ethe1 and then re-nable it and if the gateway has changed, the primary does not come back up.

Current script, which fails
Note1: comment=BellFibre refers to the comment line for the VLAN interface that data actually travels on vice the ether interface
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
":if (\$bound=1) do={ /ip route set [find commen\
t=\"BellFibre\"] gateway=(\$\"gateway-address\") disabled=no; :log warning\
\_(\"New ISP1 gateway: \".(\$\"gateway-address\")) }"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Alternate Script which seems to address changing the routing. What I think it says is,
get the gateway from dhcp client, then go to the ip route gateway and compare, if not the same then set it to the new gateway.

Note2: comment=bellroute refers to the comment line associated with the Primary Recursive Route
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
:local newgw [ip dhcp-client get [find interface="vlanbell"] gateway];
:local routegw [/ip route get [find comment="bellroute"] gateway ];
:if ($newgw != $routegw) do={
/ip route set [find comment="bellroute"] gateway=$newgw;
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

If the second one is a better then I need to add the secondary recursive routing too.
Do I do this....

:if ($newgw != $routegw) do={
/ip route set [find comment="recursiveroute1"] gateway=$newgw;
/ip route set [find comment="recursiveroute2"] gateway=$newgw;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Finally what is the purpose of
":if (\$bound=1)

Basically anytime the primary is not available and then becomes available, the router ensures that if a new gateway is in the mix, that the associated routes gets updated.
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Two Scripts need deciphering.

Mon Feb 22, 2021 8:48 pm

On $bound it is used in DHCP script.

https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Client
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 19103
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Two Scripts need deciphering.

Mon Feb 22, 2021 10:41 pm

Ahh I see, its a conditional thing.

If the lease is added or changed execute the script

So are you saying thats missing from the second script??
":if (\$bound=1) do=

How do I add this to the front and close off any required notation???
:local newgw [ip dhcp-client get [find interface="vlanbell"] gateway];
:local routegw [/ip route get [find comment="bellroute"] gateway ];
:if ($newgw != $routegw) do={
/ip route set [find comment="bellroute"] gateway=$newgw;
}


Can I nest two IF and DO statements even???
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Two Scripts need deciphering.

Mon Feb 22, 2021 11:08 pm

Nested if is no problem, some like this should do:
:if (test1="yes") do={
	if (test2="no) do={
		:put "test1=yes and test2=no"
		}
	}
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 19103
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Two Scripts need deciphering.

Tue Feb 23, 2021 5:35 am

:if (\$bound=1) do={
:local newgw [ip dhcp-client get [find interface="vlanbell"] gateway];
:local routegw [/ip route get [find comment="bellroute"] gateway ];
:if ($newgw != $routegw) do={
/ip route set [find comment="bellroute"] gateway=$newgw;
}
}

Where vlanbell is the interface identified in dhcp client
Where bellroute is the route indentified in iP routes (comment)

Who is online

Users browsing this forum: marcelofares and 16 guests