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
putcommand 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
ifstructure 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.