Community discussions

MikroTik App
 
rb77
just joined
Topic Author
Posts: 13
Joined: Mon Jan 25, 2021 10:16 am

Script Error

Mon Jan 25, 2021 10:26 am

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.
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Script Error

Tue Jan 26, 2021 5:27 pm

Yes, you are missing a command. 😜

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={
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3292
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script Error

Tue Jan 26, 2021 6:58 pm

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={}
}
 
rb77
just joined
Topic Author
Posts: 13
Joined: Mon Jan 25, 2021 10:16 am

Re: Script Error

Fri Jan 29, 2021 9:06 pm

Hey Thank you.
It works :-)

Who is online

Users browsing this forum: Google [Bot] and 17 guests