N
N
Nick2020-06-17 12:57:45
Mikrotik
Nick, 2020-06-17 12:57:45

Why does the script not work through Sheduler?

Script for CAPsMAN, finds devices with certain names and locks them by poppy.
If you run the script from the terminal /system script run 0, then everything is ok.
If you start using Sheduler or the Run button in /system/scripts, then it does not work.

:foreach i in=[/ip dhcp-server lease find ] do={
:foreach v in={"droid";"hone";"edmi";"amsung";"alaxy";"eizu";"UAWEI";"EIZU"} do={
:if (([:len [:find [/ip dhcp-server lease get $i value-name=host-name] $v ]]!=0) and ( [:len [:find [/ip dhcp-server lease get $i value-name=active-server] "SSID" ]]!=0)) do={
:global mac [/ip dhcp-server lease get $i mac-address]
:global host [/ip dhcp-server lease get $i host-name]
:global macm ([:pick $mac 0 12] . "00:00")
:if ([/cap access-list find where mac-address=$macm]="") do={/caps-man access-list add mac-address=$macm mac-address-mask=FF:FF:FF:FF:00:00 ssid-regexp=SSID action=reject place-before=0 comment=$host}
:log info "Block $host"}}}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick, 2020-06-18
@anemuk

Rewrote the script. Everything works like this

/ip dhcp-server lease {
           :foreach i in=[find (active-server=SSID && status="bound")] do={
               :local hostname [get $i host-name]
               :local vendor [:toarray "droid,hone,edmi,amsung,alaxy,eizu,UAWEI,EIZU"]
               :foreach n in=$vendor do={
                   :if ($hostname~"$n") do={
                       :local mac [get $i active-mac-address]
                       :local macm ([:pick $mac 0 12] . "00:00");
                       :if ([/caps-man access-list find where mac-address=$macm]="") do={
                           /caps-man access-list add mac-address=$macm mac-address-mask=FF:FF:FF:FF:00:00 ssid-regexp=SSID action=reject place-before=0 comment=$hostname
                           :log info "Block $hostname"
                       }
                       /ip dhcp-server lease remove $i
                       :log info "Deleted from DHCP $hostname $mac"
                   }
               }
           }
       }

K
Kirill Vasiliev, 2020-06-17
@vasilevkirill

show what the record in the scheduler looks like

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question