Community discussions

MikroTik App
 
User avatar
cfikes
Member Candidate
Member Candidate
Topic Author
Posts: 106
Joined: Mon Dec 08, 2014 9:14 pm
Location: Texas
Contact:

Scripting - Strange behavior in selector

Fri Oct 20, 2023 8:58 pm

Working on an initial configuration script that can be uploaded to a switch through winbox and applied upon reset of configuration. The script has some variables at the top to build out the vlan database, settings and so on. Everything in the script works except adding the pvid to the ether ports. There is some strange behavior on a selector, but only when its being used with a set on the port command.


Lines 59 and 60 work as expected and assign the ports to the bridge.
# Assign Ports to Bridge
:foreach i in=[/interface/find default-name~"ether"] do={ /interface/bridge/port/add bridge=$BridgeName interface=$i }
:foreach i in=[/interface/find default-name~"sfp"] do={ /interface/bridge/port/add bridge=$BridgeName interface=$i } 

Lines 68 and 69 uses the same selector, but skips "ether1" and includes "sfp-sfpplus1"
# Configure Access Ports
:if ($ConfigAccess = true) do={
    :foreach i in=[/interface/find default-name~"ether"] do={ /interface/bridge/port/set $i pvid=$AccessVLAN frame-types=admit-only-untagged-and-priority-tagged }
    }

Hardware I'm testing on is a CRS328-24P-4S+ running 7.11.2 with the firmware matching. I have attached the script if anyone is interested.
You do not have the required permissions to view the files attached to this post.
 
User avatar
cfikes
Member Candidate
Member Candidate
Topic Author
Posts: 106
Joined: Mon Dec 08, 2014 9:14 pm
Location: Texas
Contact:

Re: Scripting - Strange behavior in selector

Fri Oct 20, 2023 9:30 pm

I tried it in EVE on an older firmware 7.6 with the same behavior. Skipped ether1. So I am missing something . . . .
Screenshot 2023-10-20 132807.png
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting - Strange behavior in selector

Fri Oct 20, 2023 9:35 pm

NOTE: entry ".id" have nothing to do with VLAN ID

The script is a vomit, very mess, entry ".id" of VLAN is mixed with the entry ".id" of the interfaces, etc.

:if ($ConfigAccess = true) do={
:foreach i in=[/interface/find default-name~"ether"] do={ /interface/bridge/port/set $i pvid=$AccessVLAN frame-types=admit-only-untagged-and-priority-tagged }
}

foreach entry id of interface, set on bridge port the random item that for coincidence have same entry id... etc.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting - Strange behavior in selector  [SOLVED]

Fri Oct 20, 2023 9:44 pm

The correct way is something like this:

untested unguaranted code

:if ($ConfigAccess) do={
    :foreach ifIndex in=[/interface find where default-name~"ether"] do={
        :local ifName [/interface get $ifIndex name]
        /interface bridge port set [find where bridge=$BridgeName and interface=$ifName] pvid=$AccessVLAN frame-types=admit-only-untagged-and-priority-tagged
    }
}
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3505
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Scripting - Strange behavior in selector

Fri Oct 20, 2023 10:05 pm

I suspect the ":if ($ConfigAccess = true)" is the cause... if $ConfigAccess is not defined with a type of bool, that won't work. Note the difference in @rextended version where it will "cast" any type to a bool vs explicitly looking for boolean "true" in the variable.
 
User avatar
cfikes
Member Candidate
Member Candidate
Topic Author
Posts: 106
Joined: Mon Dec 08, 2014 9:14 pm
Location: Texas
Contact:

Re: Scripting - Strange behavior in selector

Fri Oct 20, 2023 11:29 pm

Appreciate the input everyone. Obviously have some growth potential with the tik scripting lol.

Never disappointed with the kind words from the community.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting - Strange behavior in selector

Sat Oct 21, 2023 10:40 am

Never disappointed with the kind words from the community.
:-P
It's one thing to write a complaint needlessly.
It loses meaning, indeed it becomes ridiculous for those who write it, if the reason is not explained.

My goal was to force you to pay attention to the answer, I don't make perfect scripts either,
but it's ridiculous if someone complains about it without explaining why and how it should have been done... ;)
 
User avatar
cfikes
Member Candidate
Member Candidate
Topic Author
Posts: 106
Joined: Mon Dec 08, 2014 9:14 pm
Location: Texas
Contact:

Re: Scripting - Strange behavior in selector

Sun Oct 22, 2023 12:23 am

Never disappointed with the kind words from the community.
:-P
It's one thing to write a complaint needlessly.
It loses meaning, indeed it becomes ridiculous for those who write it, if the reason is not explained.

My goal was to force you to pay attention to the answer, I don't make perfect scripts either,
but it's ridiculous if someone complains about it without explaining why and how it should have been done... ;)

I truly have nothing but respect for the knowledge you possess, where I feel there could be a change is in the initial interactions you have with individuals. Starting with words like vomit as to what someone is trying to accomplish is generally looked at as insulting. I had a genuine question, did not understand that the index was being returned and not the name, you provided an answer, which i am grateful for and have learned from, but the initial interaction was interpreted as insulting. Do you care, probably not, do I care if you care, not really either.

Again, thank you for your assistance and look forward to learning more from the plethora of scripts you have graced the community with.
 
User avatar
cfikes
Member Candidate
Member Candidate
Topic Author
Posts: 106
Joined: Mon Dec 08, 2014 9:14 pm
Location: Texas
Contact:

Re: Scripting - Strange behavior in selector

Sun Oct 22, 2023 12:35 am

Do you care, probably not, do I care if you care, not really either.
That was rude and needless, I apologize.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting - Strange behavior in selector

Sun Oct 22, 2023 12:19 pm

Do you care, probably not, do I care if you care, not really either.
That was rude and needless, I apologize.
Don't worry, I'm not offended, there are other things that offend me...
As I was telling you, by drawing attention at the beginning, the user are more likely to understand what is written next, for various reasons that I won't list now ;)

Who is online

Users browsing this forum: No registered users and 8 guests