Community discussions

MikroTik App
 
awarmanf
just joined
Topic Author
Posts: 15
Joined: Thu Apr 03, 2008 2:04 pm

How to make scheduler based on days of the week ?

Thu Jan 26, 2012 4:56 am

Dear All,

How to make scheduler based on days of the week ?
In linux, we can make schedule like this with cron:

00 08 * * 1,2,3,4,5 /usr/local/bin/script-a
00 17 * * 1,2,3,4,5 /usr/local/bin/script-b

At 08:00 on Mon, Tue, Wed, Thu, and Friday (office hours) do execute script-a.
At 17:00 on Mon, Tue, Wed, Thu, and Friday (non-office hours) do execute script-b.

Can we make it happen with mikrotik ?

Another thing, I can not display day of week on mikrotik.
Mikrotik only show date.

/system clock print
time: 09:25:26
date: jan/26/2012
time-zone-name: Asia/Jakarta
gmt-offset: +07:00

Maybe I miss some information ?

Thank in advance.
 
siprox
Frequent Visitor
Frequent Visitor
Posts: 83
Joined: Fri Apr 01, 2011 11:14 am

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 8:30 am

i think command built in to get day of week is not possible on Mikrotik, cmiiw.
but, you can try script this referenced from wiki, http://wiki.mikrotik.com/wiki/Script_to ... f_the_week. submitted by another user.
hope this help, im not trying that script.
 
awarmanf
just joined
Topic Author
Posts: 15
Joined: Thu Apr 03, 2008 2:04 pm

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 9:02 am

i think command built in to get day of week is not possible on Mikrotik, cmiiw.
but, you can try script this referenced from wiki, http://wiki.mikrotik.com/wiki/Script_to ... f_the_week. submitted by another user.
hope this help, im not trying that script.
Matur nuwun mas.
________________
wong ndeso tenanan, ojo diguyu. ra butuh karma, butuhe cendol.
Nang kene cendol ora payu mas, sing laris euro hehehe..
 
awarmanf
just joined
Topic Author
Posts: 15
Joined: Thu Apr 03, 2008 2:04 pm

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 9:05 am

I'm executing the script on http://wiki.mikrotik.com/wiki/Script_to ... f_the_week
But the result is not satisified me.
/system script> run day-of-the-week 
jan/26/2012 is on a fri
Well, now is still thursday.
 
siprox
Frequent Visitor
Frequent Visitor
Posts: 83
Joined: Fri Apr 01, 2011 11:14 am

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 10:14 am

try change this :local sum 0 to
:local sum -1

..but i don't know what will be effect later, im not coders.
 
User avatar
huigezi
newbie
Posts: 43
Joined: Sat Dec 24, 2011 4:39 am
Location: apple

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 10:26 am

:do {
:local date [/system clock get date]
:local result ""
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"]
:local monthtbl [:toarray "0,3,3,6,1,4,6,2,5,0,3,5"]
:local daytbl [:toarray "sun,mon,tue,wed,thu,fri,sat"]
:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do={:set year ($yearc)}
:local sum 0
:set sum ($sum + (2 * (3 - ($century - (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }}
:set sum (($sum - (($sum / 7) * 7))-1)
:set result [:pick $daytbl $sum]
:put ($date . " is on a " . $result)}
 
siprox
Frequent Visitor
Frequent Visitor
Posts: 83
Joined: Fri Apr 01, 2011 11:14 am

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 10:47 am

:do {
:local date [/system clock get date]
:local result ""
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"]
:local monthtbl [:toarray "0,3,3,6,1,4,6,2,5,0,3,5"]
:local daytbl [:toarray "sun,mon,tue,wed,thu,fri,sat"]
:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do={:set year ($yearc)}
:local sum 0
:set sum ($sum + (2 * (3 - ($century - (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }}
:set sum (($sum - (($sum / 7) * 7))-1)
:set result [:pick $daytbl $sum]
:put ($date . " is on a " . $result)}
did you test it?, cos i was testing it and the $result give me fri, not thu. today is thu.
 
User avatar
huigezi
newbie
Posts: 43
Joined: Sat Dec 24, 2011 4:39 am
Location: apple

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 10:53 am

today is thu i test is on thu

script is working fine
You do not have the required permissions to view the files attached to this post.
 
siprox
Frequent Visitor
Frequent Visitor
Posts: 83
Joined: Fri Apr 01, 2011 11:14 am

Re: How to make scheduler based on days of the week ?

Thu Jan 26, 2012 11:02 am

today is thu i test is on thu

script is working fine
oh great, sorry my bad. i re-test and now true. thanks a lot.
 
spotts78
newbie
Posts: 31
Joined: Thu Dec 03, 2009 5:59 pm
Location: Greensboro, NC - USA

Re: How to make scheduler based on days of the week ?

Fri Feb 03, 2012 10:34 am

Please take a look at this post http://forum.mikrotik.com/viewtopic.php?f=2&t=59029 and help me test the code. I get bad results with the script from the wiki as well.
 
ManyX
Member Candidate
Member Candidate
Posts: 111
Joined: Sat Jan 07, 2006 12:48 pm
Location: PolanD

Re: How to make scheduler based on days of the week ?

Sat Mar 31, 2012 12:31 pm

Script don't work - look for my result
You do not have the required permissions to view the files attached to this post.