การตั้ง Scheduler ในอุปกรณ์ Mikrotik เพื่อทำการ Block User ตามช่วงเวลา
เนื่องจากมีสมาชิกท่านนึงสอบถามเรื่อง Schedule เข้ามา เรื่องการ Block User ไม่ให้เข้าใช้งาน Internet ตามช่วงเวลา
....อยากจะบอกว่า อุปกรณ์ Mikrotik RouterBoard นอกจากให้ไปซื้อโอเลี้ยงแล้ว น่าจะทำได้หมดครับ

ตัวอย่างจะเป็นการกำหนด User Profile จำนวน 2 กลุ่ม โดยกลุ่ม 1 ให้เข้าใช้งาน Internet (Login เข้าใช้งาน) ได้เวลา 12.00-13.00น. และกลุ่ม 2 ใช้งานได้ 8.00 - 9.00 และ 12.00 - 13.00 น.
1. สร้าง User Profile ขึ้นมา จากตัวอย่างจะชื่อ userprofile1 และ userprofile2


2. สร้าง User โดยกำหนด Profile จากที่สร้างไว้ ตัวอย่าง
User: yod, user1 จะเป็น Profile: userprofile1 และ User: user2 จะเป็น userprofile2



3. Run script ที่ New Terminal โดยผมจะตั้งชื่อ block-user-grp1, block-user-grp1 เพื่อทำการ Disable/Enable userprof1
และ block-user-grp2, nblock-user-grp2 เพื่อทำการ Disable/Enable userprof2
เพิ่ม Script สำหรับ Delete User ที่ Active หลังจาก Disable ครับ
/system script
add name=block-user-grp1 policy=read,write source="/ip hotspot user disable [find profile=userprof1]\r\
\n:local i\r\
\n:foreach i in=[ /ip hotspot user find where disabled=yes ] do={\r\
\n:local name [/ip hotspot user get \$i name]\r\
\n[ /ip hotspot active remove [find where user=\$user] ]\r\
\n#:log info \$name\r\
\n}"
add name=block-user-grp2 policy=read,write source="/ip hotspot user disable [find profile=userprof2]\r\
\n:local i\r\
\n:foreach i in=[ /ip hotspot user find where disabled=yes ] do={\r\
\n:local name [/ip hotspot user get \$i name]\r\
\n[ /ip hotspot active remove [find where user=\$user] ]\r\
\n#:log info \$name\r\
\n}"
เคาะ enter บรรทัดสุดท้ายด้วยนะครับ

3. ทดสอบ Run script ที่ Menu System --> Script จะมีการ Disable/Enable รายชื่อ User ตามที่กำหนด User profile ไว้

4. สร้าง Schedule สำหนับ Run Script ตามเวลาที่ต้องการ
Star-Date ไม่ต้องแก้ไขอะไรครับ ส่วน Start-Time แก้ไขเวลาตามต้องการได้เลยครับ
system scheduler add name=start-unblock-user-grp1 start-date=nov/06/2012 start-time=12:00:00 interval=1d on-event=unblock-user-grp1 policy=read,write
system scheduler add name=start-block-user-grp1 start-date=nov/06/2012 start-time=13:00:00 interval=1d on-event=block-user-grp1 policy=read,write
system scheduler add name=start-unblock-user-grp2-t1 start-date=nov/06/2012 start-time=08:00:00 interval=1d on-event=unblock-user-grp2 policy=read,write
system scheduler add name=start-block-user-grp2-t1 start-date=nov/06/2012 start-time=09:00:00 interval=1d on-event=block-user-grp2 policy=read,write
system scheduler add name=start-unblock-user-grp2-t2 start-date=nov/06/2012 start-time=12:00:00 interval=1d on-event=unblock-user-grp1 policy=read,write
system scheduler add name=start-block-user-grp2-t2 start-date=nov/06/2012 start-time=13:00:00 interval=1d on-event=block-user-grp1 policy=read,write

ตรวจสอบ Scheduler ที่ Menu --> System --> Scheduler

เรียบร้อยครับ

สามารถใช้หลักการ Scheduler ร่วมกับ Function อื่นๆใน Mikrotik ที่สามารถ Ebable/Disable ได้ทุกๆ Function เลยครับ
Linkback: https://sysnetcenter.com/board/index.php?topic=1816.0