Syntax
This comprehensive syntax reference covers all aspects of RouterOS scripting language, from basic variables to advanced control structures.
Script structure and basics
Script execution context
# Scripts can be executed in multiple ways:
# 1. Direct execution in terminal
{
/log info "Direct execution";
:local message "Hello World";
/log info $message;
}
# 2. Stored script execution
/system script add name=my-script source={
/log info "Stored script execution";
}
/system script run my-script
# 3. Scheduler execution
/system scheduler add name=scheduled-task interval=1h on-event={
/log info "Scheduled execution";
}
# 4. Event-triggered execution (inline)
/ip firewall filter add chain=input action=log log-prefix="BLOCKED" \
src-address-list=blocked-ipsComments and documentation
Variables and data types
Variable declaration and naming
Data type examples
Operators and expressions
Arithmetic operators
Comparison operators
Logical operators
String operators
Control structures
Conditional statements
Loop structures
Functions and procedures
Built-in function usage
Custom function definition
Array and data structure manipulation
Array operations
Associative arrays (dictionaries)
Error handling and flow control
Exception handling
Advanced syntax features
Pattern matching and regular expressions
Dynamic command execution
This comprehensive syntax reference covers all major aspects of RouterOS scripting language, providing the foundation for creating powerful automation scripts.
Last updated
Was this helpful?