Page 1 of 1
How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 4:56 am
by awarmanf
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.
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 8:30 am
by siprox
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.
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 9:02 am
by awarmanf
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..
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 9:05 am
by awarmanf
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.
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 10:14 am
by siprox
try change this :local sum 0 to
:local sum -1
..but i don't know what will be effect later, im not coders.
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 10:26 am
by huigezi
: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)}
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 10:47 am
by siprox
: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.
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 10:53 am
by huigezi
today is thu i test is on thu
script is working fine
Re: How to make scheduler based on days of the week ?
Posted: Thu Jan 26, 2012 11:02 am
by siprox
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.
Re: How to make scheduler based on days of the week ?
Posted: Fri Feb 03, 2012 10:34 am
by spotts78
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.
Re: How to make scheduler based on days of the week ?
Posted: Sat Mar 31, 2012 12:31 pm
by ManyX
Script don't work - look for my result