# Schedule & script for Microtik

**URL:** <https://wargeeks.org/t/schedule-script-for-microtik/355>\
**Category:** Software\
**Created:** [August 7, 2014, 1:35pm UTC](https://wargeeks.org/t/schedule-script-for-microtik/355 "2014-08-07T13:35:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![InsanityFlea](https://wargeeks.org/user_avatar/wargeeks.org/insanityflea/32/1059_2.png) [@InsanityFlea](https://wargeeks.org/u/InsanityFlea)\
**Post date:** [August 7, 2014, 1:35pm UTC](https://wargeeks.org/t/schedule-script-for-microtik/355/1 "2014-08-07T13:35:20Z")

</div>

I have the following four scripts which will enable and disable the various ISP’s Each one is set to a separate interface.

[code]/system script  
add name=EnableISP1 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source=“interface pppoe enable pppoe-out1”

add name=DisableISP1 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source=“interface pppoe disable pppoe-out1”

add name=EnableISP2 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source=“interface pppoe enable pppoe-out2”

add name=DisableISP2 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source=“interface pppoe disable pppoe-out2”[/code]

Now the scheduler is where I’m lost.

I need to trigger the above scripts at certain times, weekdays and not on weekends.

EnableISP1 - Weekdays 6:00am till 6:00pm  
EnableISP2 - Weekdays 6:00pm till 6:00am & all weekend

If anyone knows how please help me out.

Here’s the scheduler documentation:  
[http://wiki.mikrotik.com/wiki/Manual:System/Scheduler](http://wiki.mikrotik.com/wiki/Manual:System/Scheduler)

It’s easy to trigger it everyday, but that’s not ideal. I could add a 5 day interval but how would that work if the router reboots? It would reset the day interval :s

`/system scheduler 
add name="Enable ISP1" interval=12h start-time=06:00:00
add name="Disable ISP1" interval=12h start-time=17:59:50
add name="Enable ISP2" interval=12h start-time=18:00:00
add name="Disable ISP2" interval=12h start-time:05:59:50`

An advanced way would be a script that runs every few seconds to check day & time then IF Monday \> 06:00 \< 18:00 then disable isp2 and enable isp1 etc.

This is a script I use for updating dynamic DNS: (runs every 5 minutes)

[code]##############Script Settings##################

:local NOIPUser “[no-ip.com](http://no-ip.com) LOGIN”  
:local NOIPPass “[no-ip.com](http://no-ip.com) PASSWORD”  
:local WANInter “MikroTik Router WAN Interface Name”

###############################################

:local NOIPDomain “$[NOIPUser.no-ip.org](http://NOIPUser.no-ip.org)”  
:local IpCurrent [/ip address get [find interface=$WANInter] address];  
:for i from=( [:len $IpCurrent] - 1) to=0 do={  
:if ( [:pick $IpCurrent $i] = “/”) do={  
:local NewIP [:pick $IpCurrent 0 $i];  
:if ([:resolve $NOIPDomain] != $NewIP) do={  
/tool fetch mode=http user=$NOIPUser password=$NOIPPass url=“[http://dynupdate.no-ip.com/nic/update\3Fhostname=$NOIPDomain&myip=$NewIP](http://dynupdate.no-ip.com/nic/update%5C3Fhostname=%24NOIPDomain&myip=%24NewIP)” keep-result=no  
:log info “NO-IP Update: $NOIPDomain - $NewIP”  
}  
}  
}[/code]

some examples: [http://wiki.mikrotik.com/wiki/Manual:Scripting-examples](http://wiki.mikrotik.com/wiki/Manual:Scripting-examples)

---

<div class="post-metadata">

**Author:** ![arby](https://wargeeks.org/user_avatar/wargeeks.org/arby/32/3_2.png) [@arby](https://wargeeks.org/u/arby)\
**Post date:** [August 7, 2014, 4:54pm UTC](https://wargeeks.org/t/schedule-script-for-microtik/355/2 "2014-08-07T16:54:16Z")

</div>

Hmm never scehduled anything on mikrotik, pity they dont just stick to a standard crontab config on the routers considering they run a linux kernel.

---

<div class="post-metadata">

**Author:** ![InsanityFlea](https://wargeeks.org/user_avatar/wargeeks.org/insanityflea/32/1059_2.png) [@InsanityFlea](https://wargeeks.org/u/InsanityFlea)\
**Post date:** [August 7, 2014, 7:09pm UTC](https://wargeeks.org/t/schedule-script-for-microtik/355/3 "2014-08-07T19:09:46Z")

</div>

yay got it

[code]/system scheduler  
add interval=1d name=peak on-event=start\_peak policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=aug/07/2014 start-time=06:00:00  
add interval=1d name=offpeak on-event=start\_offpeak policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=aug/07/2014 start-time=18:00:00  
add interval=1w name=week on-event=enable\_switch policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=aug/11/2014 start-time=00:00:00  
add interval=1w name=weekend on-event=disable\_switch policy= reboot,read,write,policy,test,password,sniff,sensitive start-date=aug/09/2014 start-time=00:00:00

/system script  
add name=start\_peak policy=reboot,read,write,policy,test,password,sniff,sensitive source=  
"/interface pppoe-client disable pppoe-out2  
/interface pppoe-client enable pppoe-out1"  
add name=start\_offpeak policy=reboot,read,write,policy,test,password,sniff,sensitive source=  
"/interface pppoe-client disable pppoe-out1  
/interface pppoe-client enable pppoe-out2"  
add name=enable\_switch policy=reboot,read,write,policy,test,password,sniff,sensitive source="/system scheduler enable [/system scheduler find name=peak] /system scheduler enable [/system scheduler find name=offpeak]“  
add name=disable\_switch policy=reboot,read,write,policy,test,password,sniff,sensitive source=”/system scheduler disable [/system scheduler find name=peak] /system scheduler disable [/system scheduler find name=offpeak]"[/code]

What this does:

4 schedules: 1st one runs the peak times, 2nd runs off-peak times, 3rd one disables the peak & off-peak schedules on a weekend. 4th one enables the peak & offpeak schedules after the weekend.
