Community discussions

MikroTik App
 
tsaqif
just joined
Topic Author
Posts: 1
Joined: Tue Dec 02, 2014 11:01 am

[ASK] SCRIPT FOR EDITING RULES

Tue Dec 02, 2014 11:19 am

Hi All,
I need your help..
Here i'm editing some rules with loop operation in queue simple with this script =

# :for x from=1 to=5 do={/queue simple set $x max-limit=512k/512k}

but there's a problem while i entered that script.

instead of repeating these scripts one by one (it's running but will take so long if there are 100 lines and more) =
# queue simple set 1 max-limit=512k/512k
# queue simple set 2 max-limit=512k/512k
# queue simple set 3 max-limit=512k/512k
# queue simple set 4 max-limit=512k/512k
# queue simple set 5 max-limit=512k/512k

anyone can correct my first script above...
thanks before.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: [ASK] SCRIPT FOR EDITING RULES

Mon Dec 08, 2014 10:01 pm

Are you trying to change ALL queues or just a range of them?

If you only want to change a range, your code is fine. But, first you must use the print command to generate the number for each item. If you don't use the print command, it doesn't know what item corresponds to which number. Something like this:
/queue simple
print without-paging
:for x from=1 to=5 do={
  set $x max-limit=512k/512k
}
If you want to change all of them, it's pretty easy, something like this:
/queue simple
:foreach x in=[find] do={
  set $x max-limit=512k/512k
}
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [ASK] SCRIPT FOR EDITING RULES

Tue Dec 09, 2014 6:12 pm

Note that if you want to modify all items or items matching a particular criteria, you can also use "find" as a subcommand, perhaps with the criteria being further specified, e.g.
/queue simple set [find] max-limit=512k/512k
to modify all, or
/queue simple set [find where max-limit=2M/2M] max-limit=512k/512k
to modify all queues who's current max-limit is 2M/2M.

On a related note, if you know in advance the exact numbers you'll be modifying, you can use
/queue simple set "1,2,3,4,5" max-limit=512k/512k
(after previously issuing a print)

Or better yet, you can use the names, e.g.
/queue simple set "queue1,queue2,queue3,queue4,queue5" max-limit=512k/512k

All of these make for significantly more efficient scripts.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: [ASK] SCRIPT FOR EDITING RULES

Tue Dec 09, 2014 6:51 pm

Nice! I had not heard of these methods before. Good to know.