Automating Network Management and Troubleshooting with Operation Scripts
Operation scripts are scripts that you write to automate network management and troubleshooting tasks. They can perform any function available through Junos XML protocol remote procedure calls (RPCs).
This section contains the following topics:
- Operation Script Overview
- Enabling Operation Scripts
- Executing Operation Scripts
- Disabling Operation Scripts
Operation Script Overview
You can execute operation scripts from the Junos OS CLI or from within an event policy. For information about event policies, see Running Self-Diagnostics with Event Policies.
Operation scripts allow you to perform various actions, including the following:
- Automatically diagnose and fix problems in your network by building and running an operational mode command, receiving the command output, inspecting the output, and determining the next appropriate action. This process can be repeated until the source of the problem is determined and reported to the CLI.
- Monitor the overall status of the device by creating a general operation script that periodically checks network warning parameters, such as high CPU usage. The general operation script can be overridden by user-defined scripts.
- Customize the output of CLI operational mode commands using printf statements.
- If there is a known problem in Junos OS, an operation script can ensure your device is configured to avoid or work around the problem.
- Change your device's configuration in response to a problem.
The scripting language you use for writing operation scripts is Extensible Stylesheet Language Transformations (XSLT). XSLT operation scripts are based on Junos XML protocol Extensible Markup Language (XML).
Enabling Operation Scripts
To enable operation scripts:
- Write an operation script.
For information about writing operation scripts, see the Junos Configuration and Operations Automation Guide.
- Copy the script to the /var/db/scripts/op directory.
Only users with superuser privileges can access and edit files in the /var/db/scripts/op directory.
- Navigate to the top of the configuration hierarchy in either the J-Web or CLI configuration editor.
- Perform the configuration tasks described in Table 48.
- If you are finished configuring the network, commit the configuration.
Table 48: Enabling Operation Scripts
Task | J-Web Configuration Editor | CLI Configuration Editor |
|---|---|---|
Navigate to the Op level in the configuration hierarchy. |
| From the [edit] hierarchy level, enter edit system scripts op |
Enable the operation script file—for example, op-script.xsl. |
| Set the script file name: set file op-script.xsl |
Executing Operation Scripts
You can execute the enabled operation scripts from the CLI or from within an event policy. For information about event policy, see Running Self-Diagnostics with Event Policies.
This section describes how you can execute operation scripts from the command line.
To execute an operation script from the CLI:
- Enter configuration mode in the CLI.
- Execute the script with the following command:
user@host# op filename.xsl
Disabling Operation Scripts
If you do not want an operation script to run, you can disable it by deleting or deactivating it in the configuration. Deleting an operation script permanently removes it from the configuration. To run the script later, you must reenable the script as described in Enabling Operation Scripts. Deactivating an operation script disables the script until you activate it later.
To delete an operation script, do the following:
- From configuration mode in the
CLI, enter the following command:
user@host# delete system scripts op filename.xsl - Commit the configuration:
user@host# commitcommit complete
To deactivate an operation script:
- From configuration mode in the
CLI, enter the following command:
user@host# deactivate system scripts op filename.xsl - Commit the configuration:
user@host# commitcommit complete

Note: You can later reactivate the operation script using the activate system scripts op filename.xsl command.
Hide Navigation Pane
Show Navigation Pane
Download
SHA1