Make your router run Scripts!

Make your router run Scripts!

RouterOS Scripting: An Introduction

Overview of RouterOS Scripting

  • RouterOS features its own scripting language, allowing users to automate various tasks on their routers without needing advanced programming skills.
  • The scripting process is similar to languages like Bash and Python, enabling direct command input in the terminal for testing and execution.

Creating and Storing Scripts

  • Instead of traditional script files, scripts are stored in the system script section of RouterOS for better organization and permission management.
  • Users can begin by naming their script, which opens a basic text editor with syntax highlighting for entering commands.

Variables and Data Types

  • RouterOS supports 11 data types that are automatically recognized upon assignment; no prior declaration is needed.
  • Variables can be declared as local or global. Local variables are created using a colon followed by "local" and the variable name.

Using Commands and Scope Management

  • The put command displays variable values; local variables disappear after execution while global ones remain in RAM until cleared.
  • It's recommended to use local variables due to their limited scope, avoiding unnecessary use of global variables.

Arithmetic Operations and Conditional Statements

  • RouterOS scripting includes typical arithmetic operators but lacks a power operator; bitwise operations may occur if incorrect symbols are used.
  • Conditional statements can be implemented using an if structure followed by actions enclosed in curly brackets.

Functions, Loops, and Automation Potential

  • Functions are defined similarly to variables but include action commands. A simple loop can call these functions for repetitive tasks.
  • The potential for automation is significant with built-in triggers like Scheduler, Netwatch, and DHCP actions available within RouterOS scripting.
Video description

Mikrotik routers have their own scripting language and it is incredible what you can do with it. https://help.mikrotik.com/docs/display/ROS/Scripting 0:00 Intro 1:04 add script 1:21 script editor 1:47 variables 2:01 local-global and :put 3:12 environment 3:55 operators and :set 4:35 conditional statements 5:05 functions and loops