Community discussions

MikroTik App
 
handiansudianto
newbie
Topic Author
Posts: 42
Joined: Fri Feb 03, 2023 5:35 am

Schedule

Thu Apr 25, 2024 4:25 pm

Anyone know how to make an schedule to run a script every date 11 each month?
 
UkRainUa
newbie
Posts: 27
Joined: Sun Mar 10, 2024 3:10 am

Re: Schedule

Fri Apr 26, 2024 1:23 am

I don't know exactly how, but you can check every day
:if (11 = [:pick begin=8 end=10 [/system/clock/get date as-string]] do={...} else={...}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12025
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Schedule

Fri Apr 26, 2024 10:10 am

Please, when you open a topic, give it a relevant title,
otherwise if all the topics on the scheduler were called "Scheduler" you know what a mess.


Schedule something each day, and on sceduler on on-event:

v6 and v7 getday code

# create a function getday that return the current day set on RouterOS, as number
:global getday do={
    /system clock                                    ; # go to system clock subsection
    :local vdate [get date]                          ; # put the current date into the variable vdate
    :local vdoff [:toarray "0,4,5,7,8,10"]           ; # create one array vdoff with the year, month, and day position on the vdate string
    :if ($vdate ~ ".../../....") do={                ; # if the date is on old format mmm/dd/yyy
        :set vdoff [:toarray "7,11,1,3,4,6"]         ; #     set vdoff with the correct values for old format
    }
    :local dd [:pick $vdate ($vdoff->4) ($vdoff->5)] ; # pick the day from vdate, the starting and ending points are read from vdoff position 4 and 5
    :return [:tonum $dd]                             ; # convert the string 01..31 to a number, and return that value
}

:if ([$getday] = 11)  do={

# call or put the script here

}
Last edited by rextended on Fri Apr 26, 2024 12:57 pm, edited 3 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12025
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Schedule

Fri Apr 26, 2024 10:15 am

:if (11 = [:pick begin=8 end=10 [/system/clock/get date as-string]] do={...} else={...}
Fun...

Don't write things at random or made up from who knows what, and at least try them before writing them on the forum.
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1087
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: Schedule

Fri Apr 26, 2024 12:08 pm

What's wrong with that suggestion? Imo, it's simple and easy to understand.
:if (26 = [:pick begin=8 end=10 [/system/clock/get date as-string]]) do={ :put "today is the 26th" }

or perpahs
:local day [:pick begin=8 end=10 [/system/clock/get date as-string]]

:if ($day = 26) do={ 
    :put "today is the 26th" 
    # let's do something today..
} 
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12025
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Schedule

Fri Apr 26, 2024 12:36 pm

I add a comment to each line, now is more clear..........


What's wrong with that suggestion? Imo, it's simple and easy to understand.
Is untested and do not work (ignoring the "..." ), and do not work on all v6 / v7.10- / 7.10+ , since the OP do not specify the version.
is less readable and confusing "if the 11 is the day" if (11 = day) versus "if the day is the 11th" if (day = 11)
Also on your script you write $day = 26 and not 26 = $day

Separate question: why "as-string"?
Actually 7.14.3 return "str" regardless is used or not as-string....

Who is online

Users browsing this forum: No registered users and 14 guests