Community discussions

MikroTik App
 
IsThisMicLive
just joined
Topic Author
Posts: 4
Joined: Thu Jun 16, 2022 4:10 am

How to use a variable part of of a command line?

Mon Nov 14, 2022 12:43 am

In order to make my installation script easier to read, I would to do the following in my command line script. I suspect the answer is easy, but so far I have not been able to figure out how to get the command line processor to substitute the text into the command line.
:global accessPort "ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged"
:global trunkPort  "ingress-filtering=yes frame-types=admit-only-vlan-tagged"
:global hybridPort "ingress-filtering=yes frame-types=admit-all"

/interface bridge port
set bridge=BR1 $hybridPort [find interface=ether3] pvid=108  comment="Hybrid Port (X8_IoT)" 
set bridge=BR1 $trunkPort  [find interface=ether4] pvid=1    comment="Trunk Port (default)"  
set bridge=BR1 $accessPort [find interface=ether5] pvid=101  comment="Access Port (X1_Base)"   
set bridge=BR1 $hybridPort [find interface=sfp1]   pvid=1    comment="Hybrid Port (default)" 

Edit Update:
Based on the input from @rextended, the following code snippet accomplishes what I was trying aiming for:
:global accessPort "ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged"
:global trunkPort  "ingress-filtering=yes frame-types=admit-only-vlan-tagged"
:global hybridPort "ingress-filtering=yes frame-types=admit-all"

:global ibp "/interface bridge port"
[:parse "$ibp set bridge=BR1 $hybridPort [find interface=ether3] pvid=108  comment=\"Hybrid Port (X8_IoT)\"" ]
[:parse "$ibp set bridge=BR1 $trunkPort  [find interface=ether4] pvid=1    comment=\"Trunk Port (default)\"" ]
[:parse "$ibp set bridge=BR1 $accessPort [find interface=ether5] pvid=101  comment=\"Access Port (X1_Base)\"" ]
[:parse "$ibp set bridge=BR1 $hybridPort [find interface=sfp1]   pvid=1    comment=\"Hybrid Port (default)\"" ]
Last edited by IsThisMicLive on Mon Nov 14, 2022 4:17 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 9569
Joined: Tue Feb 25, 2014 12:49 pm
Location: 🇮🇹, my 💔 is in 🇺🇦

Re: How to use a variable part of of a command line?

Mon Nov 14, 2022 2:25 am

accessPort is simply a string, can not be treated as command,
you can use :parse but every line must be like:
:parse "/interface bridge port set bridge=BR1 $hybridPort [find interface=ether3] pvid=108  comment=\"Hybrid Port (X8_IoT)\""
 
IsThisMicLive
just joined
Topic Author
Posts: 4
Joined: Thu Jun 16, 2022 4:10 am

Re: How to use a variable part of of a command line?

Mon Nov 14, 2022 2:55 am

So that is interesting. There is no way to construct a long command line by substituting in portions of the command from a variable? I had assumed there was some mechanism where :put could be used to combine the elements.

On the :parse option, I must still be missing something. I pasted the following into my SSH terminal window — on the one hand, no errors; but, on the other, nothing changed either.
global hybridPort "ingress-filtering=yes frame-types=admit-all"

/interface bridge port
:parse "set bridge=BR1 $hybridPort [find interface=ether3] pvid=108  comment=\"Test A\""

:parse "/interface bridge port set bridge=BR1 $hybridPort [find interface=ether3] pvid=108  comment=\"Test B\""
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 9569
Joined: Tue Feb 25, 2014 12:49 pm
Location: 🇮🇹, my 💔 is in 🇺🇦

Re: How to use a variable part of of a command line?  [SOLVED]

Mon Nov 14, 2022 3:32 am

the previous is only one example, use [ ] with :parse and /interface bridge port must be inside, not outside

[:parse "/interface bridge port print"]

Who is online

Users browsing this forum: martincz8, Semrush [Bot] and 24 guests