Community discussions

MikroTik App
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Check presence of a parameter

Thu Jun 17, 2021 11:38 pm

Hi,

I'm writing a script that updates some MikroTik equipment (update packages) and since now it worked perfectly but I ran into an issue. When I update older equipment that still does not have the "installation" parameter in the wireless interface, the default value is set to "Outdoor" and I lose the connection with my AP because the frequency is not compatible.

For stopping this issue, I create a scheduler that runs on startup and change the value of "installation" to "Any" and then removes itself. The real problem is there. If, for any reason, the update did not work, the script won't work either and will stay in the equipment (which then causes future updates not to work since the script is already there and I must delete it before).

I tried using the "execute" command so that if the code is invalid, it won't crash and will just skip this part, but is seems that I can't get the result of execute (I can get the ID but I don't get how to use it).

Is there any way to check if "installation" parameter exists?

Or any other way for that script to work :
/system scheduler add disabled=no name="tempSchedChangeInstallation" \
    on-event=("
        :if ((:typeof [(:execute {[/interface wireless get wlan1 installation]})]) != \"nil\") do={
            /interface wireless set installation=any wlan1;
            :do {
                :delay 5;
            } while=((:execute {[/interface wireless get wlan1 installation]} != \"any\"));
        }
        /system scheduler remove tempSchedChangeInstallation;") \
    policy="write" start-time=startup;
It basically checks if installation exist, if not (the update did not work), it deletes the scheduler immediately, but if it exists, it changes the "installation parameter" then wait until the change has occured and deletes itself (without the delay, the script can't remove itself since it is still running).

Thank you! :)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 4804
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Check presence of a parameter

Fri Jun 18, 2021 2:42 pm

You treat the problem on a wrong way

I hope you talk about update the CPE / Client

Fact:
Starting from 6.43.8 installation parameter are added
If you update the RouterBOARD you already know what version are used for upgrade

Self destructing script with set installation=any if find corret routeros version:
add name=startup on-event=":delay 10s;\r\
    \n:if ([/sys pack upd get installed-version]=\"6.47.10\") do={:execute \"/int wire set [find] installation=any\"};\r\
    \n/sys scheduler remove [find where name=startup];" policy=read,write start-time=startup
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 4804
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Check presence of a parameter

Fri Jun 18, 2021 3:23 pm

Is there any way to check if "installation" parameter exists?
Yes:
:global WireInstSup false
:execute "/int wire get [ find default-name=wlan1 ] installation;:set \$WireInstSup true"
:delay 1s
:put "Wireless parameter Installation supported: $WireInstSup"

:global WireATPMSup false
:execute "/int wire get [ find default-name=wlan1 ] atpm;:set \$WireATPMSup true"
:delay 1s
:put "Wireless ATPM supported: $WireATPMSup"
keep the delay, or if the CLI are faster than background "execute" you read too soon the value
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Re: Check presence of a parameter

Fri Jun 18, 2021 6:04 pm

Thank you so much!

I've tried different ways of doing that, but did not thought of this one. This really helps :)

Who is online

Users browsing this forum: alidamji, jayro2035, Yoncu and 15 guests