Community discussions

MikroTik App
 
User avatar
m3das
just joined
Topic Author
Posts: 14
Joined: Thu Feb 23, 2023 6:10 pm

Add the total output

Tue Dec 26, 2023 2:51 pm

Hello, anyone who can help me with my script. I want to add all the output total from my script.

Image
/ip hotspot
:foreach i in=[user find where name!="admin" and name!="default-trial" and disabled=no and comment!=" "] do={
    :local aUsrcomm [user get $i comment]
    :local aUsrcomm [:toarray $aUsrcomm];
    :local itotal [:tonum ($aUsrcomm->1)];
  
    :log info $itotal;
}
the output is
5
5
5
5
5

the output should be 25.
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: Add the total output  [SOLVED]

Tue Dec 26, 2023 2:55 pm

Do you know what a variable is and what the + sign means?

Since I can not work on your machine and I do not have your settings, this is untested.

untested code

{
/ip hotspot user

:local tmp ""
:local tot 0

:foreach i in=[find where name!="admin" and name!="default-trial" and disabled=no and comment!=" "] do={
    :set tmp [:toarray [get $i comment] ]
    :set tot ($tot + [:tonum ($tmp->1) ] )
}

:log info "Total is $tot"
}
Last edited by rextended on Wed Dec 27, 2023 10:26 am, edited 1 time in total.
 
User avatar
m3das
just joined
Topic Author
Posts: 14
Joined: Thu Feb 23, 2023 6:10 pm

Re: Add the total output

Tue Dec 26, 2023 3:37 pm

sorry i don't know the syntax.

your script working. @rextended thank you very much for your very fast respond. :D

Who is online

Users browsing this forum: No registered users and 10 guests