mikrotik-routeros-rsc

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: 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

快速工作流

  1. Define script objective and scope.
  2. Apply idempotent patterns (see References).
  3. Validate syntax and risks with the linter (scripts/lint_rsc.py).
  4. Test import with
    dry-run
    and
    on-error
    .
  5. Import in a controlled manner to production.
  1. 定义脚本目标与范围。
  2. 应用幂等模式(参见参考资料)。
  3. 使用代码检查工具(scripts/lint_rsc.py)验证语法与风险。
  4. 利用
    dry-run
    on-error
    测试导入。
  5. 以受控方式导入到生产环境。

Essential practices

核心最佳实践

  • Prefer
    find where ...
    + conditionals before
    add
    /
    set
    .
  • Avoid broad policies in
    /system script add policy=...
    .
  • Use
    :onerror
    and
    :jobname
    for robustness and single instance.
  • Never include destructive commands (
    system reset-configuration
    , etc.).
  • Parameterize and isolate scopes (
    :local
    vs
    :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):
    • import test.rsc verbose=yes dry-run
      to find multiple errors without applying changes.
    • do { import test.rsc } on-error={ :put "Failure" }
      to capture error.
    • onerror e in={ import test.rsc } do={ :put "Failure - $e" }
      for detailed message.
  • 代码检查:
    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,
    dry-run
    and
    onerror
    : see references/RSC_GUIDE.md
  • 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
    onerror
    :参见references/RSC_GUIDE.md
  • 安全与幂等性最佳实践:参见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
    print as-value
    , arrays, and
    where
    filters for robust queries.
  • For scheduled execution, use Scheduler with appropriate permissions.
  • 脚本应与RouterOS v7保持一致(优先推荐),并尽可能兼容v6版本。
  • 使用
    print as-value
    、数组和
    where
    过滤器实现可靠查询。
  • 如需定时执行,请使用具备适当权限的Scheduler(任务计划器)。