exactly that's what i want .[moderator action]
If this is exact case, you don't need persistence, you can just toggle enabled/disabled state on rules./routing rule enable number=0
/routing rule disable number=2
:delay 1440m
/routing rule enable number=2
/routing rule disable number=0
/routing/rule
set disabled=(![get value-name=disabled 0]) 0
set disabled=(![get value-name=disabled 2]) 2
You can put code into scheduler with 1440min interval and startup time.i want from it to run forever..with no interruption.
Generally you can achieve persistence by writing into files or comments, but for your example it is not needed.in some way i want from my router to remember the last state -(i mean if my router in second section ((/routing rule enable number=2
/routing rule disable number=0)) if he rebooted i want from it to continue here not to begain from the begining ).
[moderator action]You can put code into scheduler with 1440min interval and startup time.[/b]
can you explain more..?
It will switch disabled state of rules, if rule is disabled it will switch to enabled and vice versa. You just need initially to set states of rues different, eg: 0 - enabled, 2 - disabled. Rules will then switch states when executed.
/routing/rule
set disabled=(![get value-name=disabled 0]) 0
set disabled=(![get value-name=disabled 2]) 2
so what you mean by this rule..? what it is going to do..?
This will create scheduler for 24h interval (1440min) started on router boot (startup) with script code from above:You can put code into scheduler with 1440min interval and startup time.
can you explain more..?
/system/scheduler add name=switch-route-rules interval="1d 00:00:00" start-time=startup on-event="/routing/rule; set disabled=(![get value-name=disabled 0]) 0; set disabled=(![get value-name=disabled 2]) 2"
can you explain more..?
/system scheduler
add interval=2d name=enable-routing-rule-a on-event="/routing rule\r\
\nenable [find where comment~\"Rule A\"]\r\
\ndisable [find where comment~\"Rule B\"]\r\
\n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/01/2023 start-time=04:00:00
add interval=2d name=enable-routing-rule-b on-event="/routing rule\r\
\nenable [find where comment~\"Rule B\"]\r\
\ndisable [find where comment~\"Rule A\"]\r\
\n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/02/2023 start-time=04:00:00
True, but it covers example for OP question, I didn't bother to explain how to create script that identify rules, eg. by setting some comment on them and find them by it. Since it is seems it will raise more questions about how it works, I'm just lazy (or have more important things to spend time)5) Yur script is wrong, never use number= because numbers can vary and work only on terminal.
6) And also [get value-name=disabled 0] is wrong, for the same reason.
No matter if sometime work or not.
but in this case we didn't get rid from our problem.It will switch disabled state of rules, if rule is disabled it will switch to enabled and vice versa. You just need initially to set states of rues different, eg: 0 - enabled, 2 - disabled. Rules will then switch states when executed.
/routing/rule
set disabled=(![get value-name=disabled 0]) 0
set disabled=(![get value-name=disabled 2]) 2
so what you mean by this rule..? what it is going to do..?This will create scheduler for 24h interval (1440min) started on router boot (startup) with script code from above:You can put code into scheduler with 1440min interval and startup time.
can you explain more..?
Refer to scheduler manual if you need additional info for it: https://wiki.mikrotik.com/wiki/Manual:System/SchedulerCode: Select all/system/scheduler add name=switch-route-rules interval="1d 00:00:00" start-time=startup on-event="/routing/rule; set disabled=(![get value-name=disabled 0]) 0; set disabled=(![get value-name=disabled 2]) 2"
If you really need to be exactly 24h interval even if rebooted, then create scheduler with start-time on specific time eg: start-time="00:00:00" (midnight) instead startup, then it will switch rules every midnight.
It will not if you don't set start-time to startup, instead set to some specific time of a day, that's why I wrote at the end:in your scenario if the router is rebooted your script will run
I just set there midnight to be example, set time that is best fit for you.If you really need to be exactly 24h interval even if rebooted...
but in this case we didn't get rid from our problem.
/system scheduler
add interval=2d name=enable-routing-rule-a-take1 on-event=ISP-odd-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/01/2023 start-time=04:00:00
add interval=2d name=enable-routing-rule-a-take2 on-event=ISP-odd-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/01/2023 start-time=04:15:00
add interval=2d name=enable-routing-rule-a-take3 on-event=ISP-odd-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/01/2023 start-time=04:30:00
add interval=2d name=enable-routing-rule-a-take4 on-event=ISP-odd-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/01/2023 start-time=04:45:00
add interval=2d name=enable-routing-rule-b-take1 on-event=ISP-even-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/02/2023 start-time=04:00:00
add interval=2d name=enable-routing-rule-b-take2 on-event=ISP-even-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/02/2023 start-time=04:15:00
add interval=2d name=enable-routing-rule-b-take3 on-event=ISP-even-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/02/2023 start-time=04:30:00
add interval=2d name=enable-routing-rule-b-take4 on-event=ISP-even-days policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/02/2023 start-time=04:45:00
/system scheduler
add interval=1m name=enable-daily-routing-rule on-event="/routing rule\r\
\n:if (([:pick [/system clock get date] 4 6] % 2) = 0) do={\r\
\n disable [find where (comment~\"Rule A\" and disabled=no)]\r\
\n enable [find where (comment~\"Rule B\" and disabled=yes)]\r\
\n} else={\r\
\n disable [find where (comment~\"Rule B\" and disabled=no)]\r\
\n enable [find where (comment~\"Rule A\" and disabled=yes)]\r\
\n}\r\
\n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=jan/01/1970 start-time=00:00:00
In the "XY Problem" theme... while good to deal with the reboot case BUT if router reboots that frequently... that sounds like a bigger problem here[...] my problem is when the router is rebooted -(sometime every 14 hours [...]
And another... "so in the day 15 of the month my ISP-1 supscription is end and my router with no internet until i switch it manually.", how will these scheduled routes switching cover ended subscription at specific day?In the "XY Problem" theme... while good to deal with the reboot case BUT if router reboots that frequently... that sounds like a bigger problem here[...] my problem is when the router is rebooted -(sometime every 14 hours [...]
Hello Mr.rextended..!can you explain more..?
Add to the rule "0" the comment "Rule A" (without quotes)
Add to the rule "2" the comment "Rule B" (without quotes)
Paste this on terminal.Done.Code: Select all/system scheduler add interval=2d name=enable-routing-rule-a on-event="/routing rule\r\ \nenable [find where comment~\"Rule A\"]\r\ \ndisable [find where comment~\"Rule B\"]\r\ \n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/01/2023 start-time=04:00:00 add interval=2d name=enable-routing-rule-b on-event="/routing rule\r\ \nenable [find where comment~\"Rule B\"]\r\ \ndisable [find where comment~\"Rule A\"]\r\ \n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/02/2023 start-time=04:00:00
On reboot the routerboard keep same previous routing rule enabled, and everynight @04:00 (AM) switch the two rules.
Since the schedulers are on two different days, the rules are switched correctly.
Do you also need something that if the routerboard is off at 04:00 (AM) still syncs the right rule at the start without waiting for 04:00 the next day?
exactly that's what i want..
Add to the rule "0" the comment "Rule A" (without quotes)
Add to the rule "2" the comment "Rule B" (without quotes)
Do you also need something that if the routerboard is off at 04:00 (AM) still syncs the right rule at the start without waiting for 04:00 the next day?
exactly that's what i want..
really thanksful for everyone who shared his opinion/solution here in this threadOk.... understand........
One unique scheduler, no matter when the routerboard is rebooted or for how many time is off.
No global variable, file or other frills needed. Just set the correct comments on Rule A and Rule B.
If the day is even, activate B, if it is odd, activate A.
Check constantly, change only if necessary.
Code: Select all/system scheduler add interval=1m name=enable-daily-routing-rule on-event="/routing rule\r\ \n:if (([:pick [/system clock get date] 4 6] % 2) = 0) do={\r\ \n disable [find where (comment~\"Rule A\" and disabled=no)]\r\ \n enable [find where (comment~\"Rule B\" and disabled=yes)]\r\ \n} else={\r\ \n disable [find where (comment~\"Rule B\" and disabled=no)]\r\ \n enable [find where (comment~\"Rule A\" and disabled=yes)]\r\ \n}\r\ \n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=jan/01/1970 start-time=00:00:00
also what is the purpose of this line, what it mean..?
\n:if (([:pick [/system clock get date] 4 6] % 2) = 0) do={\r\
And so what?Problem with this odd/even calculation is when end of month is odd (every 31st and on leap year 29th). It will not switch then on 1st next month (31 % 2 = 1 and 1 % 2 = 1).
give or take one day its not a big issue..!Problem with this odd/even calculation is when end of month is odd (every 31st and on leap year 29th). It will not switch then on 1st next month (31 % 2 = 1 and 1 % 2 = 1).
I was just pointing out that route switch will not always happen every day if Techsystem wasn't aware of that, nothing else...And so what?
New month, new calculations for limits, what happened last month doesn't matter.
Furthermore, if it is to be divided exactly between 31 days, the minutes in the month (if not even the seconds) must be counted and the time divided between the two connections.
Therefore, in the months of 30 and 28 days the exchange must be done every 24 hours, in the months of 31 days it must be done every 23h and ~14m,
And on bissextile Feb every 23h and ~10m......
I think you are now exaggerating.
If that's the case, perhaps scheduler should could use less than 1m be okay too. If you need to enable logging on scripts, things that run really very often start cluttering the logs is only reason why I suggest.give or take one day its not a big issue..!Problem with this odd/even calculation is when end of month is odd (every 31st and on leap year 29th). It will not switch then on 1st next month (31 % 2 = 1 and 1 % 2 = 1).
If that's the case, perhaps scheduler should could use less than 1m be okay too. If you need to enable logging on scripts, things that run really very often start cluttering the logs is only reason why I suggest.