Script Error

Hello@all,
maybe someone can help me.

Router: MikroTik hex
OS: v6.48

I´ve created a script ‘Test’ unter /system Scripts as shown below.
On execution i get the following error message:

[admin@ROUTER] > system script run Test
expected command name (line 4 column 24)


:local piholeDNS "10.0.0.1"
:local testDomain "www.google.com"

:if ([/ip firewall nat [find comment="DNS - Redirect all DNS requests to pihole"] enabled]) do={
    :do {
        :resolve $testDomain server $piholeDNS
    } on-error={
		/ip firewall nat disable [find comment="DNS - Redirect all DNS requests to pihole"]
		/ip firewall nat disable [find comment="DNS - Traffic from pihole to www"]
    }
} else={
    :do {
        :resolve $testDomain server $piholeDNS
		/ip firewall nat enable [find comment="DNS - Redirect all DNS requests to pihole"]
		/ip firewall nat enable [find comment="DNS - Traffic from pihole to www"]
    } on-error={}
}

I cannot fint the problem, maybe i´m missing something and someone can help me.

Thank you.

Yes, you are missing a command. :winking_face_with_tongue:

The fourth line should look something like this:

:if ([/ip firewall nat get [find comment="DNS - Redirect all DNS requests to pihole"] disabled] = false) do={

Since all are done in the same command folder you can go to the command folder and shorten all commands. Eks:


:local testDomain "www.google.com"
/ip firewall nat
:if ([get [find comment="DNS - Redirect all DNS requests to pihole"] disabled] = false) do={
    :do {
        :resolve $testDomain server $piholeDNS
    } on-error={
		disable [find comment="DNS - Redirect all DNS requests to pihole"]
		disable [find comment="DNS - Traffic from pihole to www"]
    }
} else={
    :do {
        :resolve $testDomain server $piholeDNS
		enable [find comment="DNS - Redirect all DNS requests to pihole"]
		enable [find comment="DNS - Traffic from pihole to www"]
    } on-error={}
}

Hey Thank you.
It works :slight_smile: