hello all
I need help
i need script makes the user uses the Internet at speeds 40k/100k
but when the total download exceeds 50 megabyte
the speed decrease to 20k/50k
and the script is daily (the counters of total download is clear at 12 am )
best regards
khalid
Assuming you’re using User Manager:
:local user
:local bytesin
:local bytesout
:local megstotal
:local user
/tool user-manager user
:foreach i in=[/tool user-manager user find subscriber=YOURSUBSCRIBERNAME ] do={
:set user [get $i name]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set megstotal (($bytesin + $bytesout) / 1000000)
:if ([$megstotal] < 50) do={
/tool user-manager user set [/tool user-manager user find user=$i] rate-limit=40k/100k
:log info “User $user Rate Limit set to 40k/100k” } else={
/tool user-manager user set [/tool user-manager user find user=$i] rate-limit=20k/50k
:log info "User $user Rate Limit set to 20k/50k }
}
Just wrote that on the fly, haven’t tested it out,
so it might have a couple of bugs.
Try that out and see if it works for you.
Take note that I think you have to reset the user’s connection for settings like that to take effect. I speak under correction though.
You’ll need to make an entry into Scheduler to let it run every 24 hours:
/system scheduler add name=DailyWhatever on-event=YourScriptName start-date=sep/28/2007 start-time=23:59:50 interval=24h
That entry will execute the script 10 seconds before midnight, tonight.
Cheers!
-Krige
thank u again
there is a problem
i add the script

and when i click on Run script the script is not work

I will debug the script through the day and give you one that works by this afternoon.
Check this post again later for a working version.
Thanks!
-Krige
dear Krige
Thank you for your interest
im waiting you and i tried with the script and it still not work
i need it very much and my mikrotik is 2.9.27
and i waiting u
best regards
khalid
The script works on my machine, running ROS 3.0rc5.
You have not answered my question from the other thread:
Are you using User Manager or PPP/secrets?
The script is written for User Manager.
If you log into your router and run the script manually,
what error message do you get?
-K
Can you clarify what is more User Manager and PPP / secrets?
User Manager:
http://wiki.mikrotik.com/wiki/MikroTik_User_Manager
While PPP/Secrets are usernames and passwords entered directly into the Mikrotik console, that will work only for that mikrotik box. The PPP/Secrets are checked to do auths before it checks the user manager (or radius) for logins.
i m using hotspot and winbox to manage the server
hello i have a pc running 2.9.46 with usermanger and it dont work for me and would really like to be able to use somthing like that.
thanks
I gave you a script illustrating the principles,
and told you that I have not tested it,
or tried debugging it.
Has anyone attempted debugging?
Here’s a working version under ROS 3.0rc5:
:local user
:local bytesin
:local bytesout
:local megstotal
/tool user-manager user
:foreach i in=[/tool user-manager user find subscriber=admin] do={
:set user [get $i name]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set megstotal (($bytesin + $bytesout) / 1000000)
:if ([$megstotal] < 50) do={
/tool user-manager user set [/tool user-manager user find name=$user] rate-limit=40k/100k
:put $user
:put $megstotal
:put “User Rate Limit set to 40-100”} else={
/tool user-manager user set [/tool user-manager user find name=$user] rate-limit=20k/50k
:put $user
:put $megstotal
:put “User Rate Limit set to 20-50”}
}
Please make sure you understand what each and every command does before implementing this into your network.
-K
hello
thanks for the help but i am still having trouble . i am not sure how to debug it.. i get the different colors when i execute but i am not sure where the problem is.. here is the error that i get and i have tried on v3.0rc5 and also latest stable version..
[admin@MikroTik] > :local user
[admin@MikroTik] > :local bytesin
[admin@MikroTik] > :local bytesout
[admin@MikroTik] > :local megstotal
[admin@MikroTik] >
[admin@MikroTik] > /tool user-manager user
[admin@MikroTik] /tool user-manager user> :foreach i in=[/tool user-manager user
find subscriber=admin] do={
{…
{… :set user [get $i name]
expected variable name (line 3 column 6)
[admin@MikroTik] /tool user-manager user> :set bytesin [get $i download-used]
expected variable name (line 1 column 6)
[admin@MikroTik] /tool user-manager user> :set bytesout [get $i upload-used]
expected variable name (line 1 column 6)
[admin@MikroTik] /tool user-manager user> :set megstotal (($bytesin + $bytesout)
/ 1000000)
expected variable name (line 1 column 6)
[admin@MikroTik] /tool user-manager user>
[admin@MikroTik] /tool user-manager user> :if ([$megstotal] < 50) do={
syntax error (line 1 column ![]()
[admin@MikroTik] /tool user-manager user> /tool user-manager user set [/tool use
r-manager user find name=$user] rate-limit=40k/100k
syntax error (line 1 column 65)
[admin@MikroTik] /tool user-manager user> :put $user
syntax error (line 1 column 7)
[admin@MikroTik] /tool user-manager user> :put $megstotal
syntax error (line 1 column 7)
[admin@MikroTik] /tool user-manager user> :put “User Rate Limit set to 40-100”}
else={
User Rate Limit set to 40-100
[admin@MikroTik] /tool user-manager user> /tool user-manager user set [/tool use
r-manager user find name=$user] rate-limit=20k/50k
syntax error (line 1 column 65)
[admin@MikroTik] /tool user-manager user> :put $user
syntax error (line 1 column 7)
[admin@MikroTik] /tool user-manager user> :put $megstotal
syntax error (line 1 column 7)
[admin@MikroTik] /tool user-manager user> :put “User Rate Limit set to 20-50”}
User Rate Limit set to 20-50
put all your script in { } this will be treated as one script
in your case each line is different scripts and as you can read in 3.0 changelog variables must be declared before use, but if you declare local variable in one script it is not passed to another.:
works correctly in 3.0rc5, havnt figured it out yet in the stable version
thanks…
is there any way that i can make it take a look at the speed that the customer has right now and set the speed to half that and then reset itself at midnight.. as we have several different packages… or say find rate 40/100 and set it to 20/80 if over 20mb and find rate 70/200 and set it to 50/150 if over 40mb ect.
thanks
i am not all that good with scripting but am trying to learn .. i have been setting here for 8 solid hours trying to figure this out..
to get curretn rate limit
/tool user-manager user get [/tool user-manager user find name=$user] rate-limit
Add scheduler to run every 24 hours starting at midnight that runs reset script.
this is how i have it now and it runs perfectly
{
:local user
:local bytesin
:local bytesout
:local megstotal
/tool user-manager user
:foreach i in=[/tool user-manager user find subscriber=admin] do={
:set user [get $i name]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set megstotal (($bytesin + $bytesout) / 1000000)
:if ([$megstotal] < 100) do={
/tool user-manager user set [/tool user-manager user find name=$user] rate-limit=" 128k/256k 256k/384k 64k/128k 30/30 6 16k/32k"
:put $user
:put $megstotal
:put “User Rate Limit set to 128/256”} else={
/tool user-manager user set [/tool user-manager user find name=$user] rate-limit=" 64k/64k 128k/128 64k/64k 30/30 8 16k/32k"
:put $user
:put $megstotal
:put “User Rate Limit set to 64k/64k”}
}
}
}
it put the burst and everthing in there..
with the midnight script what exactly will happen??? this script will run and will set bandwith correct?? what i really need to do is check this say every hour and if they have used over the limit it takes them offline so that the new bandwith rule will go into effect and or is there a way to do that dynamiclly and then at midnight reset there bandwith back to what it should be..
thanks a ton
p.s i was thinking and it seems that the total bytes in + out runs as a total and we would really like to keep a record of how much bandwith has been used during the time that $cleint has been a cleint. so how do i figure this out to not count total bandwith just bandwith used on a day to day basis? somthing to do with adding the date ???
Since the original script is mine, I’ll be happy to consult on adapting it.
The download-used and upload-used attributes in the /tool/user-manager/user section is the Total downloads since Sign-Up, or since it was last reset. Resetting this does not affect the counters you will see in User Manager web interface’s reports generator.
The long-term records are kept in /tool/user-manager/log.
In other words, you’ll still have a record of your user’s usage since he/she signed up, even after you’ve run the Reset-Counters command.
So tell me exactly what you need, and let’s take it from there.
-Krige
thanks very much for your help.. what i do not understand is the reset part of the script or is that a totally differnt script? also i would like to figure out how to make the script to look for $user under ip hotspot active user and log them off if they have used more bandwith than the set limit .. as from what i uderstand just changing the settings in usermanager does not have any effect until the user logs off and back on.. once i figure out how to do this i plan to implement it on a 4 hour basis to set users bandwith… another cool idea would be for it to check the group id of user in usermanager and if it is say A it applies but if not it has no effect.. that way i can set varios differnt plans with group id and it would be very useful…
thanks in advance..
The resetting can be implemented in the same script.
As for changes in user manager having no effect until you reconnect - That’s correct.
I’m sure it is possible to disconnect a user under ip-hotspot, much the same you can terminate a PPPoE connection by killing it in /interface/pppoe-server/
I will look into it after I get some sleep. Just got back from an all-nighter work session and the sun is already out. Oy.
but how do i make it reset the counters i cant seem to figure that one out..
thanks