Community discussions

MikroTik App
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sun Sep 20, 2015 5:33 am

# This Part works fine #
{
:local date [ /system clock get date ]
:if ( [ /ip hotspot user get $user comment ] = "" ) do={
[ /ip hotspot user set $user comment=$date ]
}
}

# The Problematic Part comes here #
{
:local offset 7
:global today

{
:local date [ /system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=$months do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where disabled=no ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt ] )
:for nodays from=0 to=$months do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:log info "HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date"
[ /ip hotspot user disable $i ]
[ /ip hotspot active remove [find where user=$user] ]
}
}
}
}

# The new terminal error message #
invalid value of "to", must be integer

NORMIS, PLEASE HELP ME TO DO THE SCRIPT COME BACK TO WORK FINE !!!!!!!!!!!!!!!!!!!!!!!!!!!
 
User avatar
JJCinAZ
Member
Member
Posts: 476
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Tue Sep 22, 2015 12:39 am

Everywhere you have:
:for nodays from=0 to=$months do={
Try using:
:for nodays from=0 to=[:tonum $months] do={
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Wed Sep 23, 2015 2:39 am

Everywhere you have:
:for nodays from=0 to=$months do={
Try using:
:for nodays from=0 to=[:tonum $months] do={
Thank you! Your code works! You are great!

# This her is my own Version #
# Important: always set the limit-uptime under ip-hotspot user # :D :lol: :)

{
:local date [ /system clock get date ]
:if ( [ /ip hotspot user get $user comment ] = "" ) do={
[ /ip hotspot user set $user comment="$date"]
}
}
:foreach h in=[/ip hotspot active find] do={
:global user [/ip hotspot active get $h user];
:global mac [/ip hotspot active get $h mac-address];
/ip hotspot user set $user mac=$mac
}
{
:foreach h in=[/ip hotspot active find] do={
:local user [/ip hotspot active get $h user];
:local mac [/ip hotspot active get $h mac-address];
:local logdate [/ip hotspot user get $user comment];
:local date [/system clock get date];
:local time [/system clock get time];
:local upt [/ip hotspot user get $user limit-uptime];
/system scheduler remove [/system scheduler find name="$user"];
/system scheduler add comment="$date . $time" interval=$upt name="$user" on-event="/ip\
\_hotspot active remove [/ip hotspot active find user=\"$user\"]\r\
\n/ip hotspot user disable [/ip hotspot user find name=\"$user\"]\r\
\n/ip hotspot cookie remove [/ip hotspot cookie find name=\"$user\"]\r\
\n/system scheduler remove [/system scheduler find name=\"$user\"]" \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive \
start-date=$logdate start-time=12:00:00
}
}
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 4:18 pm

There is a new error! This is very Curios!

{
:local offset 2
:global today

{
:local date [ /system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where profile=PRIVATE ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt ] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:log info "HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date"
[ /ip hotspot user disable $i ]
}
}
}
}

# By profile=PRIVATE NewTerminal error ,,invalid value of "to", must be integer" #


{
:local offset 2
:global today

{
:local date [ /system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where profile=10RS ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt ] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:log info "HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date"
[ /ip hotspot user disable $i ]
}
}
}
}

# By profile=10RS without error, NewTerminal O.K, why ???????????????? #
 
User avatar
JJCinAZ
Member
Member
Posts: 476
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 5:21 pm

You should try inserting some ":log info ()" commands to debug your code. For example
...

:foreach i in [ /ip hotspot user find where profile=PRIVATE ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:log info ($days)
:local monthtxt [ :pick $date 0 3 ]
:log info ($monthtxt)
:local year [ :pick $date 7 11 ]
:log info ($year)
:local months ( [ :find $montharray $monthtxt ] )
:log info ($months)
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}

...
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 5:36 pm

the result is
script info th
script info HP
script info r

what I not understand is
when I change the profile from the user the script runs very well, when I change the profile in users other time back to my custumated the error comes back
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 6:00 pm

{
:local offset 1
:global today

{
:local date [ /system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where profile=1000 ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:log info ($days)
:local monthtxt [ :pick $date 0 3 ]
:log info ($monthtxt)
:local year [ :pick $date 7 11 ]
:log info ($year)
:local months ( [ :find $montharray $monthtxt ] )
:log info ($months)
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:local mac [/ip hotspot user get $i mac-address]
:local mail [/ip hotspot user get $i email]
:local time [/system clock get time]
:local cdate [/system clock get date]
:log info "HOTSPOT EXPIRE SCRIPT: Sending email to Hotspot user $name first logged in $date"
[ /tool e-mail send to="$mail" from="5g.net" subject=("Aviso 5G Net" . " -- " . "Usoario=$name" . " -- " . "Seu Mac=$mac") body=\
"AVISO SUA RECARGA VAI VENCER !!!
Sua Recarga vai vencer nos proximos 24 Horas, use todos os Gigabytes ou Megabytes restantes imediatamente !!!
Sua Recarga atual foi ativado no Dia-$date !!!
Nome do Usoario=$name, O Mac do seu Dispositivo=$mac
Esta Mensagem foi enviado em-$cdate, Horas-$time
Muito Obrigado dos seus Amigos da 5G Net de Novo Progresso, PA, CEP 68193-000, Brasil" ]
}
}
}
}

# invalid value of "to", must be integer #
# script info th
script info HP
script info r
script info #


# now I change the profile=270RS in hotspot user #


{
:local offset 1
:global today

{
:local date [ /system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where profile=270RS ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:log info ($days)
:local monthtxt [ :pick $date 0 3 ]
:log info ($monthtxt)
:local year [ :pick $date 7 11 ]
:log info ($year)
:local months ( [ :find $montharray $monthtxt ] )
:log info ($months)
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:local mac [/ip hotspot user get $i mac-address]
:local mail [/ip hotspot user get $i email]
:local time [/system clock get time]
:local cdate [/system clock get date]
:log info "HOTSPOT EXPIRE SCRIPT: Sending email to Hotspot user $name first logged in $date"
[ /tool e-mail send to="$mail" from="5g.net" subject=("Aviso 5G Net" . " -- " . "Usoario=$name" . " -- " . "Seu Mac=$mac") body=\
"AVISO SUA RECARGA VAI VENCER !!!
Sua Recarga vai vencer nos proximos 24 Horas, use todos os Gigabytes ou Megabytes restantes imediatamente !!!
Sua Recarga atual foi ativado no Dia-$date !!!
Nome do Usoario=$name, O Mac do seu Dispositivo=$mac
Esta Mensagem foi enviado em-$cdate, Horas-$time
Muito Obrigado dos seus Amigos da 5G Net de Novo Progresso, PA, CEP 68193-000, Brasil" ]
}
}
}
}

# email send O.K, New Terminal no error,
script info 10
script info oct
script info 2015
script info 9

My email client thunderbird receifed

AVISO SUA RECARGA VAI VENCER !!!
Sua Recarga vai vencer nos proximos 24 Horas, use todos os Gigabytes ou Megabytes restantes imediatamente !!!
Sua Recarga atual foi ativado no Dia-oct/10/2015 !!!
Nome do Usoario=Sa, O Mac do seu Dispositivo=94:51:03:D3:B6:B8
Esta Mensagem foi enviado em-oct/19/2015, Horas-12:55:04
Muito Obrigado dos seus Amigos da 5G Net de Novo Progresso, PA, CEP 68193-000, Brasil #
 
User avatar
JJCinAZ
Member
Member
Posts: 476
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 6:16 pm

Right, so $days is wrong and that comes from the variable $date which comes from a hotspot user comment:
:local date [ /ip hotspot user get $i comment ]
So clearly, one of your hotspot users doesn't have a comment in the expected format.
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 9:34 pm

oct/10/2015
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 9:40 pm

I don't understand why this script works fine for all user profiles, error comes only by one especific profile, I doesn't change any thing from the rule, error occur when I change the profile in user profile???????????
 
User avatar
JJCinAZ
Member
Member
Posts: 476
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Mon Oct 19, 2015 9:41 pm

Try logging the date variable each time through the loop.
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Fri Oct 23, 2015 2:56 pm

I don't understand what you mean?????????????? :?
 
User avatar
JJCinAZ
Member
Member
Posts: 476
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sat Oct 24, 2015 1:16 am

Right after your line:
:local date [ /ip hotspot user get $i comment ]
Add a log:
:local date [ /ip hotspot user get $i comment ]
:log info "DATE IS:$date"
You'll see something you don't expect to be in the comment.
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sat Oct 24, 2015 12:40 pm

:foreach i in [ /ip hotspot user find where profile=1000 ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:?
 
User avatar
diodo
just joined
Posts: 8
Joined: Fri May 06, 2016 3:58 am
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Wed May 11, 2016 10:24 pm

:foreach i in [ /ip hotspot user find where profile=1000 ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:?
Dear PeterDoBrasil

Did you reach solution for your problem? I´m trying to do a script similar to yours.
 
PeterDoBrasil
Member Candidate
Member Candidate
Topic Author
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sun May 22, 2016 12:14 am

:foreach i in [ /ip hotspot user find where profile=1000 ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:?
Dear PeterDoBrasil

Did you reach solution for your problem? I´m trying to do a script similar to yours.
High Voltage has damaged my Router, I have no other device to work with Scripting now !!! :?
 
User avatar
diodo
just joined
Posts: 8
Joined: Fri May 06, 2016 3:58 am
Contact:

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sun May 22, 2016 2:16 am

Dear @PeterDoBrasil

Your script is being very useful to me. Thanks for share it on mikrotik WIKI.

I´m developing a group of scripts that should create a static user with the data of dinamic "trial hotspot user" and every LOGOUT, update the "uptime variable" of him (I´m using limit-uptime field).

Every days I run your script (with little adaptations) to know if the user spend more then 7hs in the last 7 days.

MY PROBLEM:

In "http://wiki.mikrotik.com/wiki/Manual:IP/Hotspot/User" says: "Starting with v6.34rc11 some additional variables are available:" we can find the new variable: "$uptime-secs" but using v6.35.2 or v6.34.1 the variable is not there.

Maybe your or the master @JJCinAZ can try help me.

Sorry for my bad english. My main language is portuguese. If possible call me on skype: osorio@diodo.com.br

Thank all.
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sun May 22, 2016 3:17 pm

This script has many errors !!
 
pradnyeshs
just joined
Posts: 2
Joined: Sat Nov 21, 2020 4:25 pm

Re: Expire users a after number of days Stops Work after Upgrade to v.6.33rc11

Sat Nov 21, 2020 4:35 pm

Not working in v 6.47.7

# this part works#
{
:local m [ip hotspot active get value-name=mac-address [find user=$username]]
/ip hotspot user set mac-address=$m [find name=$username]
:local date [ /system clock get date ]
:if ( [ /ip hotspot user get $user comment ] = "" ) do={
[ /ip hotspot user set $user comment=$date ]
}
}

# this part giving error#


{
:local date [ /system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ([ :find $montharray $monthtxt] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where disabled=no ] do={
:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={
:local date [ /ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt ] )
:for nodays from=0 to=[:tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:log info "HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date"
[ /ip hotspot user disable $i ]
[/ip hotspot cookie remove [find where user=$user] ]
[ /ip hotspot active remove [find where user=$user] ]
}
}
}
}


#output#

invalid value of "to", must be integer

Image

Who is online

Users browsing this forum: No registered users and 37 guests