hotspot profile vs queue simple rate

Hello everyone, i’m working on script that check profile from hotspot user and change limit at queue simple rate ,but still now it’s work on 1 profile only , if 2 users have same profile script won’t work

Ex)
User1 profile 1M (rate 0/0 like default profile)
User2 profile 2M (rate 0/0 like default profile)
User3 profile 1M (rate 0/0 like default profile)

im planing to chage rate at queue not at user profiles
:local ip [/ip hotspot user get [find profile=“1M”] address]
/ip hotspot user
:if ([/ip hotspot user find profile=“1M”] !=“”) do={
/queue simple
set [find target-addresses=(“$ip/32”)] max-limit=“256000/1024000” limit-at=“256000/1024000”
}script fail, because we have 2 users have same profile"1M"
:local ip [/ip hotspot user get [find profile=“2M”] address]
/ip hotspot user
:if ([/ip hotspot user find profile=“2M”] !=“”) do={
/queue simple
set [find target-addresses=(“$ip/32”)] max-limit=“512000/2048000” limit-at=“512000/2048000”
}script work successfully because we have 1 user only with profile"2M"

any idea to make this script work on unlimited kind or number of profiles.

Kinda regards, Torky

Using :foreach will do what you want. Use it to loop through all 1M and 2M users, and set their queues.
:foreach i in=[/ip hotspot user find profile=“1M”] do={
:local ip [/ip hotspot user get $i address]
/queue simple set [find target-addresses=(“$ip/32”)] max-limit=“256000/1024000” limit-at=“256000/1024000”
}:foreach i in=[/ip hotspot user find profile=“2M”] do={
:local ip [/ip hotspot user get $i address]
/queue simple set [find target-addresses=(“$ip/32”)] max-limit=“512000/2048000” limit-at=“512000/2048000”
}

It’s work, thanks, but this script won’t work if 1 ip is missin
EX)

user1 profile=1M address 172.185.77.3
user2 profile=1M address 172.185.77.7
user3 profile=1M address 172.185.77.9

if i deleted ip from user2 script will work only with user1 and won’t work for all users after user2 plus user2