i am trying to make a global variable to holding the number on logged user and counting it down when user goes off, another one is i want to make a script which run at every 10s interval monitoring/read this $hotspotuser var, when ever its “0”, it will enable/disable rules in queue tree, are these possible?
I don’t have no idea of scripting.. but I think it must be:
:global instead of :local?
# Before using variable in script, it's name must be introduced. There are several ways to do that: With :global. It introduces name of global variable, which is created if it doesn't exist already.
[admin@MikroTik] ip route> /
[admin@MikroTik] > :global g1
[admin@MikroTik] > :set g1 "this is global variable"
[admin@MikroTik] > :put $g1
this is global variable
[admin@MikroTik] >
Global variables can be accessed by all scripts and console logins on the same router. There is no way currently to remove global variable, except rebooting router. Variables are not kept across reboots.
# With :local. It introduces new local variable, which is not shared with any other script, other instance of the same script, other console logins. It's value is lost when script finishes or when variable name is freed by :unset.
[admin@MikroTik] > :local l1
[admin@MikroTik] > :set l1 "this is local variable"
[admin@MikroTik] > :put $l1
this is local variable
[admin@MikroTik] >
But when i tried to retrieved the $hotspotuser by “:put $hotspotuser;” on the terminal,it just show 0 which a value that i assigned before on the terminal.
Ya i was forgot to add user on hotspot, instead i am using user from userman.
Thanks but it’s always shows 0,i tried this on the terminal, “:global numberOfLoggedInUsers [:len [/ip hot
spot active]]” , and " :put $numberOfLoggedInUsers;" always shows 0, i have checked there is user logged in. and how to disabled rules in queue tree? my pseudo code would be like this :
:if ($numberOfLoggedInUsers = 0 and rule a enabled) do={ disable rule "a"}
:if ($numberOfLoggedInUsers >= 0 and rule a disabled) do={ enable rule "a"}
thanks, hmm it seem there is no comment properties on /queue tree, winbox seem only temporary save the comment if you set one, but will discard when reboot, so i use name instead :
:if ([:len [/ip hotspot active find]] > 0) do={ /queue tree set [/queue tree find name="hotspot-morning"] disabled=yes }
:if ([:len [/ip hotspot active find]] > 0) do={ /queue tree set [/queue tree find name="hotspot-morning-down"] disabled=no }
:if ([:len [/ip hotspot active find]] > 0) do={ /queue tree set [/queue tree find name="hotspot-morning-up"] disabled=no }
:if ([:len [/ip hotspot active find]] > 0) do={ /queue tree set [/queue tree find name="hotspot-night-down"] disabled=yes }
:if ([:len [/ip hotspot active find]] > 0) do={ /queue tree set [/queue tree find name="hotspot-night-up"] disabled=yes }
:if ([:len [/ip hotspot active find]] = 0) do={ /queue tree set [/queue tree find name="hotspot-morning-down"] disabled=yes }
:if ([:len [/ip hotspot active find]] = 0) do={ /queue tree set [/queue tree find name="hotspot-morning-up"] disabled=yes }
:if ([:len [/ip hotspot active find]] = 0) do={ /queue tree set [/queue tree find name="hotspot-night-down"] disabled=no }
:if ([:len [/ip hotspot active find]] = 0) do={ /queue tree set [/queue tree find name="hotspot-night-up"] disabled=no }
The code run well but as i run it every 10s,it will rereset all of queue, the connection doesn’t drop but just a little spike, is there any way to check whether a specific id properties is disabled or not and return it as bool?
pseudo code:
if(hotspotuser>0 && hotspot-morning-down.disabled=yes) do {enable hotspot-morning-down), how to do that? i was trying to get disabled properties of id but return as “*100000e” .