Help with Ping script, done something wrong. Advise please.

We have 4 links which we would like to monitor by pinging an outside ip address and if the ip address is not available, the script will move the distance of that route to 3.
In the routes we have backup links set to distance of 2. So if the link fails to ping correctly it will move the main route to a higher distance, and the lower one taking over.

Using netwatch to run the scripts every 10 mins or so.

Please can someone look over this script and let me know if it’s correct, as it dont seem to work.

Thanks.



-------------------------> Test for Link 1


:local i 0;

{

:do {

:set i ($i + 1);

} while=(($i < 5) && ([/ping 212.58.244.68 routing-table=“Link 1” interface=ether2 interval=3 count=1]=0))

:if ($i= 5 && [/ip route get [find comment=“Link 1”] distance]=1) do={

:log info “Link 1 is Down - Going to BACKUP”;

/ip route set [find comment=“Cable 1”] distance=3;

}
}


-------------------------> Test for Link 2



:local i 0;

{

:do {

:set i ($i + 1);

} while=(($i < 5) && ([/ping 212.58.244.68 routing-table=“Link 2” interface=ether2 interval=3 count=1]=0))

:if ($i= 5 && [/ip route get [find comment=“Link 2”] distance]=1) do={

:log info “Link 1 is Down - Going to BACKUP”;

/ip route set [find comment=“Link 2”] distance=3;

}
}

-------------------------> Test for Link 3


:local i 0;

{

:do {

:set i ($i + 1);

} while=(($i < 5) && ([/ping 212.58.244.68 routing-table=“Link 3” interface=ether2 interval=3 count=1]=0))

:if ($i= 5 && [/ip route get [find comment=“Link 3”] distance]=1) do={

:log info “Link 3 is Down - Going to BACKUP”;

/ip route set [find comment=“Link 3”] distance=3;

}
}


-------------------------> Test for Link 4


:local i 0;

{

:do {

:set i ($i + 1);

} while=(($i < 5) && ([/ping 212.58.244.68 routing-table=“Link 4” interface=ether2 interval=3 count=1]=0))

:if ($i= 5 && [/ip route get [find comment=“Link 4”] distance]=1) do={

:log info “Link 4 is Down - Going to BACKUP”;

/ip route set [find comment=“Link 4”] distance=3;

}
}