I have been going round and round for 2 weeks now.
I need to set a global variable at start up or at start of day to make a schedule.
I later have 1 SCRIPT that is checking several things. One of which being whether the time range falls with in the schedule.
The script appears to not process the :global variable when brought into a function so I made this smaller script just to check.
Script1
:local timetest [/system clock get time]
:local GST
:if (($timetest>09:00:00)and($timetest<17:00:00)) do={set $GST “1”} else= {set $GST “0”}
:log info “GST Status = $GST”
Works as expected.
Now Script2
:local timetest [/system clock get time]
:local GST
:local V1 “($timetest>09:00:00)and($timetest<17:00:00)”
:log info $V1
:if ($V1) do={set $GST “1”} else= {set $GST “0”}
:log info “GST Status = $GST”
This Fails right after showing me the time range.
Now if I change everything to :global… I can paste right into a terminal and see where the error is…
[admin@MikroTik] > :global timetest [/system clock get time]
[admin@MikroTik] > :global GST
[admin@MikroTik] > :global V1 “($timetest>09:00:00)and($timetest<17:00:00)”
[admin@MikroTik] > :log info $V1
[admin@MikroTik] >
[admin@MikroTik] > :if ($V1) do={set $GST “1”} else= {set $GST “0”}
conditional is not boolean
[admin@MikroTik] > :log info “GST Status = $GST”
Looking at my /system script enviornment
[admin@MikroTik] > /system script environment print
The string I need is pretty small, and needs to be updated per day.
Hence the desire to write the “string” per day then have the script reference “Today’s String” and plug it into the function.
Set your schedule…
This example will set GuestTime to True From 9:00AM-5:00PM and From 8:00PM-11:59:59PM.
:global timetest [/system clock get time]
:global TT1 do={ :return (($timetest>09:00:00)and($timetest<17:00:00)||($timetest>20:00:00))}
:local GuestTime [:put [$TT1]]