You have to create two scripts , one for disabling users at 06:00, and second for enabling them at 23:00 hrs, and schedule them as per required timings.how can i disable some of my hotspot users from 06:00 till 23:00 and enable them from 23:00 till 06:00???
# Setting Clock Time
:local CurrentTime [/system clock get time];
:log warning "Disabling Users at Current Time = $CurrentTime. . ."
# Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user
:local user1 "test1";
:local user2 "test2";
# Disabling Users ...
/ip hotspot user disable $user1
/ip hotspot user disable $user2
# Removing active users
#/ip hotspot active remove $user1
#/ip hotspot active remove $user2
:log warning "Disabling Users Completed . . ."
# Setting Clock Time
:local CurrentTime [/system clock get time];
:log warning "Enabling Users at Current Time = $CurrentTime. . ."
# Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user
:local user1 "test1";
:local user2 "test2";
# ENABLING Users ...
/ip hotspot user enable $user1
/ip hotspot user enable $user2
:log warning "ENABLING Users Completed . . ."
/system scheduler
add interval=1d name=disable-user-at-0600-hours on-event=disable-users \
policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
start-date=jan/30/2014 start-time=06:00:00
add interval=1d name=enable-users-at-2300-hours on-event=enable-users policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
start-date=jan/30/2014 start-time=23:00:00
:global content [/file get [/file find name=data.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\r\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 2 ) ;
:local entry [:toarray $line] ;
:if ( [:pick $entry] != "" ) do={
:put $entry;
#:log warning "$entry"
/ip hotspot user disable $entry;
}
} while ($lineEnd < $contentLen)
test1
test2
data.txt whare can i put it?OR you can use this too if you want to read user names via text file and act accordingly.
Sample of data.txt which contains user namesCode: Select all:global content [/file get [/file find name=data.txt] contents] ; :global contentLen [ :len $content ] ; :global lineEnd 0; :global line ""; :global lastEnd 0; :do { :set lineEnd [:find $content "\r\n" $lastEnd ] ; :set line [:pick $content $lastEnd $lineEnd] ; :set lastEnd ( $lineEnd + 2 ) ; :local entry [:toarray $line] ; :if ( [:pick $entry] != "" ) do={ :put $entry; #:log warning "$entry" /ip hotspot user disable $entry; } } while ($lineEnd < $contentLen)
Code: Select alltest1 test2
Your method is creating with winbox or user Manger?You have to create two scripts , one for disabling users at 06:00, and second for enabling them at 23:00 hrs, and schedule them as per required timings.how can i disable some of my hotspot users from 06:00 till 23:00 and enable them from 23:00 till 06:00???
DISABLE Script name: disable-usersENABLE Script name: enable-usersCode: Select all# Setting Clock Time :local CurrentTime [/system clock get time]; :log warning "Disabling Users at Current Time = $CurrentTime. . ." # Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user :local user1 "test1"; :local user2 "test2"; # Disabling Users ... /ip hotspot user disable $user1 /ip hotspot user disable $user2 # Removing active users #/ip hotspot active remove $user1 #/ip hotspot active remove $user2 :log warning "Disabling Users Completed . . ."
& Following is Scheduler Entry to run both scripts at given timings.Code: Select all# Setting Clock Time :local CurrentTime [/system clock get time]; :log warning "Enabling Users at Current Time = $CurrentTime. . ." # Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user :local user1 "test1"; :local user2 "test2"; # ENABLING Users ... /ip hotspot user enable $user1 /ip hotspot user enable $user2 :log warning "ENABLING Users Completed . . ."
This is very basic level, you can modify it as you like. For example You can shorten it by creating a text file and upload to your mikrotik, and then script take values from this file, and act accordinglyCode: Select all/system scheduler add interval=1d name=disable-user-at-0600-hours on-event=disable-users \ policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ start-date=jan/30/2014 start-time=06:00:00 add interval=1d name=enable-users-at-2300-hours on-event=enable-users policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ start-date=jan/30/2014 start-time=23:00:00
Hope it will help.
Tell me how to do if there is no user in the secret produces an error "no such item" how to work around? /ppp secret disable $entry;OR you can use this too if you want to read user names via text file and act accordingly.
Sample of data.txt which contains user namesCode: Select all:global content [/file get [/file find name=data.txt] contents] ; :global contentLen [ :len $content ] ; :global lineEnd 0; :global line ""; :global lastEnd 0; :do { :set lineEnd [:find $content "\r\n" $lastEnd ] ; :set line [:pick $content $lastEnd $lineEnd] ; :set lastEnd ( $lineEnd + 2 ) ; :local entry [:toarray $line] ; :if ( [:pick $entry] != "" ) do={ :put $entry; #:log warning "$entry" /ip hotspot user disable $entry; } } while ($lineEnd < $contentLen)
Code: Select alltest1 test2