add default route

Hi, I would like to build a script that enable “add default route” to all interface type ending “out” such (“pppoe-out”, “l2tp-out” and etc,)… I would like to know if there is a better way to do it,.. attached code that I wrote, It’s works but I would like to know if I can do it in another way (short way) such variable in command (/interface $CHANGEABLE-client set add-default-route=$drc $wan)…

:if ([:pick [/interface get value-name=type $wan] ([:find [/interface get value-name=type $wan] "-"]+1) [:len [/interface get value-name=type $wan]]]="out") do={
	:local drc
	if ([:tostr $mode]="enable") do={
		:set $drc true
	} else={
		:set $drc false
	}
	:if (([:pick [/interface get value-name=type $wan] 0 [:find [/interface get value-name=type $wan] "-"]]="pppoe") && ([/interface pppoe-client get value-name=add-default-route $wan]!=$drc)) do={
		/interface pppoe-client set add-default-route=$drc $wan
	}
	:if (([:pick [/interface get value-name=type $wan] 0 [:find [/interface get value-name=type $wan] "-"]]="l2tp") && ([/interface l2tp-client get value-name=add-default-route $wan]!=$drc)) do={
		/interface l2tp-client set add-default-route=$drc $wan
	}
	:if (([:pick [/interface get value-name=type $wan] 0 [:find [/interface get value-name=type $wan] "-"]]="ppp") && ([/interface ppp-client get value-name=add-default-route $wan]!=$drc)) do={
		/interface ppp-client set add-default-route=$drc $wan
	}
	:if (([:pick [/interface get value-name=type $wan] 0 [:find [/interface get value-name=type $wan] "-"]]="sstp") && ([/interface sstp-client get value-name=add-default-route $wan]!=$drc)) do={
		/interface sstp-client set add-default-route=$drc $wan
	}
}

This can be done during creation of the “out” interface, such as PPPoE client and DHCP client etc. All have the option to create a default route dynamically.

You didn’t understand me I already have pppoe-out interface and l2tp-out interface, I would like to do foreach interface add to default route. and I would like to know if I can combine the command into one single foreach… the commands is not same for pppoe I should do “/interface pppoe-client set add-default-route=true” and for l2tp is “/interface l2tp-client set add-default-route=true”…

This is not work:

foreach i in=[/interface find type=pppoe-out or type=l2tp-out] do={
/interface set add-default-route=true
}

I should do:

:foreach i in=[/interface find type=pppoe-out] do={
/interface pppoe-client set add-default-route=true
}
:foreach i in=[/interface find type=l2tp-out] do={
/interface l2tp-client set add-default-route=true
}

and i’m asking if there is sort why to do it, or that’s is the way (the 2nd code that works)…

How many default routes do you need to add? This could potentially destroy your network as it’s not simply adding a route, if you are running multiple routes you will need to work out the distance for each one and even then sometimes you may need to specify routing marks. This seems a bit more than what a few lines of script will do, I don’t deny it can be done but what I’m saying is that you will probably spend more time trying to make a script for single use than just applying the routes intelligently on your own.