Script keeps on disabling my LAN to WAN Links

Good Day,

Need some assistance.

Below are 2 system schedules that aren’t working correctly.
When the one schedule runs it is meant to enable the second one after running. and vice versa but they are not doing that. also not logging the information in the log file nor sending the required email. can you please assist. if there is a better way of doing it then please let me know.

add disabled=yes interval=30m name=“WAN 1 Failure Test” on-event=“ip route\r
\nset distance=1 0\r
\nset distance=1 2\r
\nenable 0\r
\n#set WAN 2 routing group distance to 2\r
\nset distance=2 1\r
\nset distance=2 3\r
\n\r
\n:if ([/ping 8.8.8.8 interface="1. WAN1" count=5]= 5) do={:log info "W
AN 1 ping successful"; /system scheduler enable "WAN 1 Test"; /system s
cheduler disable "WAN 1 Failure Test"; /tool e-mail send to="logacall@#######" subject="##### WAN 1 UP" body="###### WAN 1 co
nnections is up. All routing rules restored"; /ip route enable 1} else={:
log error "WAN 1 still Down"}” policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
start-date=sep/30/2019 start-time=13:25:00


add interval=5m name=“WAN 1 Test” on-event=“/ip route\r
\n set distance=1 0\r
\n set distance=1 2\r
\n #set WAN 2 routing group distance to 2\r
\n set distance=2 1\r
\n set distance=2 3\r
\n:if ([/ping 8.8.8.8 interface="1. WAN1" count=5]= 5) do={:log info "W
AN 1 ping successful"} else={:log error "WAN 1 Down"; /system scheduler
_disable " WAN 1 Test"; /system scheduler enable "WAN 1 Failure Test"
; /tool e-mail send to="logacall@#####" subject="##### WAN
1 DOWN" body="##### WAN 1 connections is down. All traffic set to
_go through WAN 2";/ip route \r
\ndisable 0\r
\ndisable 1\r
\nset distance=1 3}” policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
start-date=sep/30/2019 start-time=13:40:00

You should never ever address configuration items by numerical index in a script! That is guaranteed to break. Replace this:

/ ip route set distance=1 0

with something like:

/ ip route set distance=1 [ find where dst-address="0.0.0.0/0" ]

Of course you have to adopt the code to your needs. Perhaps that already solves your problems, did not look deeper into the code.

Hey,

Thank you will try that and let you know

Regards