Syed Jahanzaib Personal Blog to Share Knowledge !

December 7, 2011

Mikrotik Howto Add Schedule to Run the Script


To add schedule to run any specific script at specific scheduled time, Follow the steps Below.

1) First create the script
2) Schedule it to run it at desired time.

SCENARIO # 1 | Allow user JOHN access to internet in Lunch Timings Only . . .

You have created a rule that blocks user John internet access all the time (In this example, we disable user id JOHN, it can also be done via creating firewall rule to block access, but for this example we will use disable strategy), but you want him to use internet from 1:00pm til 2:00pm. You have to create two scripts, first that will disable the “Block user john rule” at 1 pm and the second script that will enable the “Block user john rule” at 2 pm.

Here is the “Block user john rule

/ppp secret add caller-id="" comment="" disabled=no limit-bytes-in=0 limit-bytes-out=0 local-address=10.10.0.1 name=john password=123 profile=default routes="Testing ID" service=any

Here are the Scripts examples in following screenshots.


Now ADD the following Scheduler to Execute both scripts at desired timing.

# Enable-User-John-Script at 1PM (Interval 1d so it may run every day)
# Disable-User-John-Script at 2PM (Interval 1d so it may run every day)

C.L.I  VERSION:

[admin@MikroTik] > /system script export
/system script
add name=disable-user-john-script policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="/ppp secret disable john"
add name=enable-user-john-script policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="/ppp secret enable john"

 

[admin@MikroTik] > /system scheduler export
/system scheduler
add comment="" disabled=no interval=1d name="Enable User JOHN at 1pm" on-event=Enable-user-john-script policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=dec/07/2011 start-time=13:00:00
add comment="" disabled=no interval=1d name="Disable User JOHN at 2pm" on-event=Disable-user-john-script policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=dec/07/2011 start-time=14:00:00

Another example on howto disable Web Proxy Access Rule.

SCENARIO # 2 | Block Access to Facebook, and Allow only in Lunch Timings

You have blocked access to social networking web sites Facebook and you want that users can access it only in Lunch timings, which is from 1:00pm till 2:00pm. I assume you are using Mikrotik web proxy [transparent mode], (If not, you can block the access via ip pool + firewall filter, adjust it accordingly, its only an example)

For example you have created an rule in web.proxy to block Facebook, (BLOCK-FB rule) which blocks Face-book site , example below

/ip proxy access
add action=deny comment=fb disabled=no dst-host=www.facebook.com

(Don’t forget the ‘comments’ in rule) and Now you want to Allow access to FB from 1:00 pm till 2:00 pm,
You have to create two Scripts, one that will disable the BLOCK-FB rule,
and second that will enable the BLOCK-FB rule.

Disable-fb-rule Script

/ip proxy access disable [find comment="fb"]

Enable-fb-rule Script

/ip proxy access enable [find comment="fb"]

OR you can Add scripts via following code in TERMINAL.

/system script
add name=disable-fb-rule-script policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="/ip proxy access disable [find comment=\"fb\"]"
add name=enable-fb-rule-script policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="/ip proxy access enable [find comment=\"fb\"]"

Now add schedule to Run “disable-fb-rule-script” to run at 1:00 pm Daily,
Add another schedule to Run “enable-fb-rule-script” to run at 2:00 pm Daily,

/system scheduler
add comment="" disabled=no interval=1d name="Disable fb rule schedule" on-event="disable-fb-rule-script"  start-date=dec/08/2010 start-time=01:00:00
add comment="" disabled=no interval=1d name="Enable fb rule schedule" on-event="enable-fb-rule-script"  start-date=dec/08/2010 start-time=02:00:00

SCENARIO # 3 | Reboot RB daily in  night

Following script will create a schedule, which will reboot RB daily in night at 1:00am.

/system scheduler
add comment="Reboot every 1 day" disabled=no interval=1d name=Reboot1d on-event="/system reboot" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive start-date=Nov/14/2012 start-time=01:00:00

%d bloggers like this: