Taking next run from another script

Hint #1: :pick []

return range of elements or substring. If the count is not specified, will return only one element from an array.

var - value to pick elements from
start - element to start picking from (the first element index is 0)
end - terminating index (element at this index is not included)

as from ROS scripting help.

@rextended suggested to use :pick because output date-time format has fixed number of characters and it is easy to extract them with this command, date has 10 characters and time 8, ranges for pick are easily then to find knowing that single character (space) is between.
Hint #2: 0-10, 11-19(or :len )

Ok, I understand that, I used it in the original script, but in which variable do I have to use the :PICK?

As I understand from your previous question you want date and time separately from output of $futuredatetimestr function call. Assign that ouput to variable and use pick on it.

I don’t know how to do this, please help me. Thank you.

It is hard to guide you if you don’t know ROS scripting fundamentals, study ROS Scripting help page for syntax and commands reference and learn from examples there. Manual for variables is in Scopes section, example for assigning value to variable from function: :local [$functionName …]

I have the script like this:

:local newInterval [/system scheduler get [find where name=TEST] interval]
    :local futuredatetimestr do={
    /system clock
    :local vdate [get date]
    :local vtime [get time]
    :local vgmt  [:tonum [get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
    :local prMntDays [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"]
    :local daysOnMnt [:toarray "0,31,28,31,30,31,30,31,31,30,31,30,31"]
    :local LcaseMnts [:toarray "0,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"]
    :local PcaseMnts [:toarray "0,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"]
    :local UcaseMnts [:toarray "0,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC"]
    :local LcaseWeekDays [:toarray "thu,fri,sat,sun,mon,tue,wed"]
    :local PcaseWeekDays [:toarray "Thu,Fri,Sat,Sun,Mon,Tue,Wed"]
    :local UcaseWeekDays [:toarray "THU,FRI,SAT,SUN,MON,TUE,WED"]
    :local NumbrWeekDays [:toarray "4,5,6,7,1,2,3"]
    :local Fzerofill do={:return [:pick (100 + $1) 1 3]}
    :local gmtSg "+"; :if ($vgmt < 0) do={:set gmtSg "-"; :set vgmt ($vgmt * -1)}
    :local gmtHr [:pick [:totime $vgmt] 0 2]
    :local gmtMn [:pick [:totime $vgmt] 3 5]
    :local vdoff [:toarray "0,4,5,7,8,10"]
    :local MM    [:pick $vdate ($vdoff->2) ($vdoff->3)]
    :local M     [:tonum $MM]
    :if ($vdate ~ ".../../....") do={
        :set vdoff [:toarray "7,11,1,3,4,6"]
        :set M     ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
        :if ($M>12) do={:set M ($M - 12)}
        :set MM    [:pick (100 + $M) 1 3]
    }
    :local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)]
    :local Leap "No-Leap"
    :if ((($yyyy - 1968) % 4) = 0) do={:set Leap "Leap"; :set ($prMntDays->1) -1; :set ($prMntDays->2) 30; :set ($daysOnMnt->2) 29}
    :local mmm  ($LcaseMnts->$M)
    :local Mmm  ($PcaseMnts->$M)
    :local MMM  ($UcaseMnts->$M)
    :local MD   ($daysOnMnt->$M)
    :local dd   [:pick $vdate ($vdoff->4) ($vdoff->5)]
    :local d    [:tonum $dd] ; :local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($prMntDays->$M) + ($d - 1))
    :local YD   (($prMntDays->$M) + $d)
    :local www  ($LcaseWeekDays->($totd % 7))
    :local Www  ($PcaseWeekDays->($totd % 7))
    :local WWW  ($UcaseWeekDays->($totd % 7))
    :local WD   ($NumbrWeekDays->($totd % 7))
    :local HH   [:pick $vtime 0  2]
    :local H    [:tonum $HH]
    :local hh   ([:tonum $HH] % 12); :if ($hh = 0) do={:set hh 12}; :set hh [$Fzerofill $hh]
    :local h    [:tonum $hh]
    :local a    "A"; :if ([:tonum $HH] > 11) do={:set a "P"}
    :local aa   "$a\4D"
    :local mm   [:pick $vtime 3  5]
    :local m    [:tonum $mm]
    :local ss   [:pick $vtime 6  8]
    :local s    [:tonum $ss]
    :local Z    "$gmtSg$gmtHr:$gmtMn"
    :local Unix (((((($totd * 24) + $H) * 60) + $m) * 60) + $s - $vgmt)
    # end time to unix
    # start time to seconds
    :local inTime [:totime $1]
    :local wPos   [:find $inTime "w" -1]
    :local dPos   [:find $inTime "d" -1]
    :local itLen  [:find $inTime "." -1] ; :if ([:typeof $itLen] = "nil") do={:set itLen [:len $inTime]}
    :local itSec  [:pick $inTime ($itLen - 2) $itLen]
    :local itMin  [:pick $inTime ($itLen - 5) ($itLen - 3)]
    :local itHou  [:pick $inTime ($itLen - 8) ($itLen - 6)]
    :local itDay  0
    :local itWee  0
    :if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime 0 $dPos] }
    :if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime ($wPos + 1) $dPos] }
    :if  ([:typeof $wPos] = "num")                                do={:set itWee [:pick $inTime 0 $wPos] }
    :local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee))
    # end time to seconds
    # start (unix + future seconds) to time
    :local ux ($Unix + $totitSec)
    :local Fzerofill do={:return [:pick (100 + $1) 1 3]}
    :local prMntDays [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"]
    :local vgmt      [:tonum [/system clock get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
    :if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}
    :local tzepoch   ($ux + $vgmt)
    :if ($tzepoch < 0) do={:set tzepoch 0} ; # unsupported negative unix epoch
    :local yearStart (1970 + ($tzepoch / 31536000))
    :local tmpbissex (($yearStart - 1968) / 4) ; :if ((($yearStart - 1968) % 4) = 0) do={:set ($prMntDays->1) -1 ; :set ($prMntDays->2) 30}
    :local tmpsec    ($tzepoch % 31536000)
    :local tmpdays   (($tmpsec / 86400) - $tmpbissex)
    :if (($tmpsec < (86400 * $tmpbissex)) and ((($yearStart - 1968) % 4) = 0)) do={
        :set tmpbissex ($tmpbissex - 1) ; :set ($prMntDays->1) 0 ; :set ($prMntDays->2) 31 ; :set tmpdays  ($tmpdays + 1)
    }
    :if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1) ; :set tmpdays   ($tmpdays + 365)}
    :local mnthStart 12 ; :while (($prMntDays->$mnthStart) > $tmpdays) do={:set mnthStart ($mnthStart - 1)}
    :local dayStart  [$Fzerofill (($tmpdays + 1) - ($prMntDays->$mnthStart))]
    :local timeStart (00:00:00 + [:totime ($tmpsec % 86400)])
    :return "$yearStart/$[$Fzerofill $mnthStart]/$[$Fzerofill $dayStart] $timeStart"

   :local startDate [:pick $futuredatetimestr 0 10]
   :local startTime [:pick $futuredatetimestr 11 19]
}   
   :put $startDate
   :put $startTime

And it doesn’t work.
Where’s the mistake?

If you do not know scripting, you must not alter the function.

so, between
:global futuredatetimestr do={
and
}
you must not change or add anything.


And if you have one example on how to call the function
:put [$futuredatetimestr 1d00:00:00]
you must respect that example

so:

:global futuredatetimestr do={
[...]
}
{
    :local newInterval [/system scheduler get [find where name="TEST"] interval]
    :local nsd [$futuredatetimestr $newInterval]
    :local startDate [:pick $nsd  0 10]
    :local startTime [:pick $nsd 11 19]
    :put $startDate
    :put $startTime
}

Now REX is working, one last question:
How do I mark the post as solved?

I think the initial decision to add/remove scheduled entries on per user session basis is kinda wonky. I’m just thinking some :for loop in ONE schedule script that [find]'s the particular users to cleanup would be a better approach, than re-calculating the schedule time and incurring all the config writes to flash (and logs etc).

Also, side-note, is that none of the scripts will not work on V7. So if you ever to upgrade, or acquire newer MikroTik devices that only run V7…all this work is for nothing. Now UM has changed too, so “porting” this script would not be your only problem, but does make it even more difficult to move to V7 in future.

Ok REX, but now try with

:local nextRun [/system scheduler get [find where name=TEST] next-run]

It doesn’t work for me

I feel sorry for you, it’s time you hire someone or study scripting.

We are not here to work for you, to explain to us step by step what you need and we will do it for you.

Excuse me REX, but how do I make the date mm/dd/yyyy, the month in letters please and sorry for so much trouble, not in yy/mm/dd in numbers

Friend REX, how do I make the month appear in letters and not numbers? Thanks for your help.

Friends, I need your help changing the month from numbers to letters. (Example: change it from 06 to jun). Please help me.


Only that is missing

Why don’t you try to guess at least? Plenty of clues already in the thread. Or, at least show you’ve tried something and provide error why it doesn’t work.

And just be aware NONE of this is going to work if you EVER upgrade to V7… and the whole approach to add/delete scheduled task is where this goes sideways since I have no idea why the schedule script does not just use some :for or :foreach loop.

http://forum.mikrotik.com/t/changing-from-number-to-date/150050/1

I can’t find the problem, please help.

@jaclaz
The solution is on the script itself.
The feeds are over, we are not his employees.

Friend REX, just change the month to letters, example “06 to jun”


Please appreciate your help

Please tell me in which line of the script the problem is