> ## Documentation Index
> Fetch the complete documentation index at: https://altostrat.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Script Management

> Create, test, authorize, schedule, and monitor RouterOS scripts across Altostrat SDX managed sites.

Script management is the right tool when you need direct RouterOS control across one or more sites. SDX wraps scripts in an operational lifecycle so changes can be tested, scheduled, authorized, delivered through the device job plane, and audited afterward.

Use scripts for device configuration tasks that are easier or more precise in RouterOS than in a workflow node.

## Prerequisites

Before you schedule a script, make sure you have:

* Permission to create and manage scheduled scripts.
* At least one adopted site that can receive jobs.
* A script that has been reviewed for RouterOS version compatibility.
* A test site for validation.
* An authorization path for production execution.

## Script Lifecycle

```mermaid theme={null}
stateDiagram-v2
  [*] --> Draft
  Draft --> Test: Run test
  Draft --> Unauthorized: Save scheduled script
  Unauthorized --> Scheduled: Authorized
  Scheduled --> Launched: Launch time reached
  Launched --> Completed: Site outcomes complete
  Launched --> Failed: One or more outcomes fail
  Scheduled --> Canceled: Canceled before launch
```

## Create And Run A Scheduled Script

<Steps>
  <Step title="Create the script">
    Go to **Scripts**, open **Scheduled Scripts**, then create a scheduled script. Give it a description that will still make sense in an audit trail later.
  </Step>

  <Step title="Select targets">
    Choose the sites that should receive the script. Keep the first rollout small unless the script is already proven.
  </Step>

  <Step title="Add script content">
    Write the RouterOS script directly or start from a template. Keep scripts idempotent so retries or partial rollout recovery do not create duplicate configuration.
  </Step>

  <Step title="Choose timing">
    Set the launch time. For production changes, align it with your maintenance window.
  </Step>

  <Step title="Run a test">
    Run the script against a test site before scheduling the wider rollout.
  </Step>

  <Step title="Request authorization">
    Move the script through the authorization flow before production execution.
  </Step>

  <Step title="Monitor outcomes">
    Watch each site outcome after launch. Investigate failed outcomes through site logs and orchestration history.
  </Step>
</Steps>

## Templates

Templates help you standardize repeatable scripts. Use templates for tasks your team performs more than once, such as:

* Adding common firewall rules.
* Updating service settings.
* Capturing diagnostic state.
* Applying a known workaround.
* Building version-aware script fragments.

Treat templates like production code. Name them clearly, review changes, and test before broad deployment.

## AI-Assisted Script Drafting

AI can help draft RouterOS scripts from a natural-language prompt. Use it to speed up first drafts, not to skip review.

Before running an AI-generated script:

1. Read every command.
2. Check whether it could remove access, disable services, delete configuration, or change routing.
3. Test it on a non-critical site.
4. Confirm the resulting device state is what you intended.
5. Use the normal authorization flow for production rollout.

<Warning>
  Never deploy an AI-generated RouterOS script directly to production without human review and a test run.
</Warning>

## Best Practices

<CardGroup cols={2}>
  <Card title="Keep scripts idempotent" icon="repeat">
    Check whether objects already exist before adding them. Avoid scripts that fail or duplicate state on a second run.
  </Card>

  <Card title="Use narrow targets first" icon="crosshair">
    Prove behavior on one test site, then a small cohort, before a fleet-wide launch.
  </Card>

  <Card title="Prefer templates for repeat work" icon="book-copy">
    Templates reduce copy-paste drift and make operational procedures easier to review.
  </Card>

  <Card title="Read outcomes, not just launch state" icon="list-checks">
    A launched script is not the same as a successful script. Review each site result.
  </Card>
</CardGroup>

## Related Pages

<CardGroup cols={2}>
  <Card title="Configuration backups" icon="archive" href="../fleet/configuration-backups" arrow="true">
    Create rollback points and compare device state before or after script changes.
  </Card>

  <Card title="Operational model" icon="network" href="../getting-started/operational-model" arrow="true">
    Understand how SDX delivers jobs to routers.
  </Card>
</CardGroup>
