mikrotik-routeros-rsc
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSkill: RouterOS .rsc
技能:RouterOS .rsc
This skill guides the creation, editing, and review of RouterOS (.rsc) scripts with safe and idempotent patterns, plus validation before import.
本技能指导你采用安全且幂等的模式创建、编辑和审核RouterOS(.rsc)脚本,并在导入前进行验证。
Quick workflow
快速工作流
- Define script objective and scope.
- Apply idempotent patterns (see References).
- Validate syntax and risks with the linter (scripts/lint_rsc.py).
- Test import with and
dry-run.on-error - Import in a controlled manner to production.
- 定义脚本目标与范围。
- 应用幂等模式(参见参考资料)。
- 使用代码检查工具(scripts/lint_rsc.py)验证语法与风险。
- 利用和
dry-run测试导入。on-error - 以受控方式导入到生产环境。
Essential practices
核心最佳实践
- Prefer + conditionals before
find where .../add.set - Avoid broad policies in .
/system script add policy=... - Use and
:onerrorfor robustness and single instance.:jobname - Never include destructive commands (, etc.).
system reset-configuration - Parameterize and isolate scopes (vs
:local).:global
- 优先使用+ 条件语句,再执行
find where .../add操作。set - 避免在中设置宽泛的权限策略。
/system script add policy=... - 使用和
:onerror提升脚本健壮性,确保单实例运行。:jobname - 切勿包含破坏性命令(如等)。
system reset-configuration - 参数化并隔离作用域(与
:local)。:global
Validation and testing
验证与测试
- Lint: .
python scripts/lint_rsc.py path/to/script.rsc - Safe import (RouterOS ≥ 7.16.x):
- to find multiple errors without applying changes.
import test.rsc verbose=yes dry-run - to capture error.
do { import test.rsc } on-error={ :put "Failure" } - for detailed message.
onerror e in={ import test.rsc } do={ :put "Failure - $e" }
- 代码检查:。
python scripts/lint_rsc.py path/to/script.rsc - 安全导入(RouterOS ≥ 7.16.x):
- :在不应用更改的前提下查找多个错误。
import test.rsc verbose=yes dry-run - :捕获错误。
do { import test.rsc } on-error={ :put "Failure" } - :获取详细错误信息。
onerror e in={ import test.rsc } do={ :put "Failure - $e" }
References (use as needed)
参考资料(按需使用)
- Language and syntax: see references/LANGUAGE.md
- .rsc export/import, and
dry-run: see references/RSC_GUIDE.mdonerror - Security and idempotency best practices: see references/SAFE_PRACTICES.md
- Common examples and patterns: see references/EXAMPLES.md
- Linter rules: see references/LINTER_RULES.md
- 语言与语法:参见references/LANGUAGE.md
- .rsc导出/导入、与
dry-run:参见references/RSC_GUIDE.mdonerror - 安全与幂等性最佳实践:参见references/SAFE_PRACTICES.md
- 常见示例与模式:参见references/EXAMPLES.md
- 代码检查规则:参见references/LINTER_RULES.md
Notes
注意事项
- Scripts should be consistent with RouterOS v7 (preferred) and compatible with v6 where possible.
- Use , arrays, and
print as-valuefilters for robust queries.where - For scheduled execution, use Scheduler with appropriate permissions.
- 脚本应与RouterOS v7保持一致(优先推荐),并尽可能兼容v6版本。
- 使用、数组和
print as-value过滤器实现可靠查询。where - 如需定时执行,请使用具备适当权限的Scheduler(任务计划器)。