Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Control the Execution of Commit Scripts During Commit Operations

Commit scripts are stored on a device’s hard disk in the /var/db/scripts/commit directory or on the flash drive in the /config/scripts/commit directory. Only users in the Junos OS superuser login class can access and edit files in these directories. For information about setting the storage location for scripts, see Store and Enable Junos Automation Scripts and Store Scripts in Flash Memory.

A commit script is not actually executed during commit operations unless its filename is included at the [edit system scripts commit file] hierarchy level. When you configure the script filename, you must include the appropriate filename extension for SLAX (.slax) and Python (.py) scripts. XSLT scripts do not require a filename extension, but we strongly recommend that you append the .xsl extension for clarity. To prevent execution of a commit script, delete the commit script’s filename at that hierarchy level.

By default, the commit operation fails unless all scripts included at the [edit system scripts commit file] hierarchy level actually exist in the commit script directory. To enable the commit operation to succeed even if a script is missing, include the optional statement at the [edit system scripts commit file filename] hierarchy level. For example, you might want to mark a script as optional if you anticipate the need to quickly remove it from operation by deleting it from the commit script directory, but do not want to remove the commit script filename at the [edit system scripts commit file] hierarchy level. To enable use of the script again later, you simply replace the file in the commit script directory.

CAUTION:

When you include the optional statement at the [edit system scripts commit file filename] hierarchy level, no error message is generated during the commit operation if the file does not exist. As a result, you might not be aware that a script is not executed as you expect.

You can also deactivate and reactivate commit scripts by issuing the deactivate and activate configuration mode commands. When a commit script is deactivated, the script is marked as inactive in the configuration and does not execute during the commit operation. When a commit script is reactivated, the script is again executed during the commit operation.

To determine which commit scripts are currently enabled on the device, use the show command to display the files configured at the [edit system scripts commit] hierarchy level. To ensure that the enabled files are on the device, list the contents of the /var/run/scripts/commit/ directory by using the file list /var/run/scripts/commit operational mode command.

Enabling Commit Scripts to Execute During Commit Operations

To configure a commit script to execute during a commit operation:

  1. Ensure that the commit script is located in the correct directory:
    • /var/db/scripts/commit directory on the hard disk

    • /config/scripts/commit directory on the flash drive

    For more information about script storage location, see Store and Enable Junos Automation Scripts and Store Scripts in Flash Memory.

  2. Enable the commit script by including the file filename statement at the [edit system scripts commit] hierarchy level. Only users who belong to the Junos OS super-user login class can enable commit scripts.
    • filename—Name of the commit script.

    • optional—Enable the commit operation to succeed when the script file does not exist in the script directory. If this statement is omitted, the commit operation fails if the script does not exist.

  3. For unsigned Python scripts, ensure that the following requirements are met:
    • File owner is either root or a user in the Junos OS super-user login class.

    • Only the file owner has write permission for the file.

    • The language python or language python3 statement is configured at the [edit system scripts] hierarchy level.

    Note:

    Starting in Junos OS Release 16.1R3, Python scripts can be owned by either root or a user in the Junos OS super-user login class. In Junos OS Release 16.1R2 and preceding, Python scripts must be owned by the root user.

  4. Commit the configuration.

Preventing Commit Scripts from Executing During Commit Operations

You can prevent a commit script from executing during a commit operation by removing the script’s filename from the [edit system scripts commit] hierarchy in the configuration.

Note:

You can also use the deactivate statement to deactivate a script instead of removing the script’s filename from the configuration. Deactivated scripts may be reactivated later.

To prevent a commit script from executing during a commit operation:

  1. Delete the commit script filename at the [edit system scripts commit] hierarchy level in the configuration.
  2. Commit your changes.
  3. (Optional) Remove the commit script from the commit script directory on the device.

    Although removing the commit script from the commit script directory is not required, it is always a good policy to delete unused files from the system.

Deactivating Commit Scripts

Deactivating a commit script results in its being marked as inactive in the configuration and ignored during a commit operation. You can reactivate the script by using the activate statement.

To deactivate a commit script so that it does not execute during the commit operation:

  1. Issue the deactivate command.
  2. Commit your changes.
  3. Verify that the commit script is deactivated.

Activating Commit Scripts

Deactivating a commit script results in its being marked as inactive in the configuration and is therefore not executed during the commit operation.

To activate an inactive commit script:

  1. Issue the activate command.
  2. Commit your changes.

Change History Table

Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.

Release
Description
16.1R3
Starting in Junos OS Release 16.1R3, Python scripts can be owned by either root or a user in the Junos OS super-user login class.