Here is a example config that I use for Failover no scripting needed. This is being used in production. Currently it uses Static IPs for GW.
You must adjust all gateway= and in-interface= for your config
This assumes you don't have any routing or other mangle rules to mark connections and routing marks
After adjusting for you network copy then paste in Mikrotik terminal
Randy Newman
--------
## http://http://wiki.mikrotik.com/wiki/Ad ... _Scripting
## Adapted from the above
## change gateway= to correct gw IPs
## and in-interface= in mangle rules
/ip route
## Need IP addresses to test this is in the USA
## Changed to less used sites but always up.
## If you change these you need to change all the same IPs below
# b.resolvers.Level3.net
add dst-address=4.2.2.2 gateway=192.168.10.1 scope=10
# c.resolvers.Level3.net
add dst-address=4.2.2.3 gateway=192.168.202.1 scope=10
# google-public-dns-a.google.com
add dst-address=8.8.4.4 gateway=192.168.10.1 scope=10
# dns1.rcsntx.sbcglobal.net
add dst-address=151.164.1.8 gateway=192.168.202.1 scope=10
## Now we create rules ISP1 routing mark:
add distance=1 gateway=4.2.2.2 routing-mark=to_ISP1 check-gateway=ping
add distance=2 gateway=8.8.4.4 routing-mark=to_ISP1 check-gateway=ping
## Create rules for ISP2 routing mark:
add distance=1 gateway=4.2.2.3 routing-mark=to_ISP2 check-gateway=ping
add distance=2 gateway=151.164.1.8 routing-mark=to_ISP2 check-gateway=ping
## Create destinations to "virtual" ISP1 hops to use in further routes
add dst-address=10.8.8.1 gateway=4.2.2.2 scope=10 target-scope=10 check-gateway=ping
add dst-address=10.8.8.1 gateway=8.8.4.4 scope=10 target-scope=10 check-gateway=ping
## Create destinations to "virtual" ISP2 hops to use in further routes
add dst-address=10.4.4.1 gateway=4.2.2.3 scope=10 target-scope=10 check-gateway=ping
add dst-address=10.4.4.1 gateway=151.164.1.8 scope=10 target-scope=10 check-gateway=ping
## add default routes
add distance=2 gateway=10.8.8.1 routing-mark=to_ISP1
add distance=1 gateway=10.4.4.1 routing-mark=to_ISP2
## add default routes no routing marks distance 1 for router
add distance=2 gateway=10.8.8.1
add distance=1 gateway=10.4.4.1
## Add blackhole for routeros bug if interface goes down not
## sure if still needed with current version of RouterOS
add dst-address=4.2.2.2 type=blackhole distance=20
add dst-address=4.2.2.3 type=blackhole distance=20
add dst-address=8.8.4.4 type=blackhole distance=20
add dst-address=151.164.1.8 type=blackhole distance=20
## make sure to set in-interface= to correct interface names
/ip firewall mangle
add action=mark-connection chain=input comment="mark ISP1_conn" disabled=no \
in-interface=ether1-gw-att new-connection-mark=ISP1_conn passthrough=yes
## This must be output chain
add action=mark-routing chain=output comment="mark routing isp1_conn" \
connection-mark=ISP1_conn disabled=no new-routing-mark=to_ISP1 passthrough=no
add action=mark-routing chain=prerouting comment="mark routing to_ISP1" \
connection-mark=ISP1_conn disabled=no in-interface=ether5-LAN \
new-routing-mark=to_ISP1 passthrough=yes
add action=mark-connection chain=input comment="mark ISP2_conn" disabled=no \
in-interface=ether2-gw-tw new-connection-mark=ISP2_conn passthrough=yes
## This must be output chain
add action=mark-routing chain=output comment="mark routing isp2_conn" \
connection-mark=ISP2_conn disabled=no new-routing-mark=to_ISP2 passthrough=no
add action=mark-routing chain=prerouting comment="mark routing to_ISP2" \
connection-mark=ISP2_conn disabled=no in-interface=ether5-LAN \
new-routing-mark=to_ISP2 passthrough=yes