Supported Platforms
Controlling Execution of Commit Scripts During Commit Operations
Commit scripts are stored on a device’s hard drive 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 Storing and Enabling Scripts and Storing 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. 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 included
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
using the file list /var/run/scripts/commit operational
mode command.
The filename of a commit script written in SLAX must include
the .slax
extension for the script
to be executed. No filename extension is required for commit scripts
written in XSLT, but we strongly recommend
that you append the .xsl
extension.
See the following sections:
Enabling Commit Scripts to Execute During Commit Operations
To configure a commit script to execute during a commit operation, follow these steps:
- Ensure that the commit script is located in the correct
directory: the
/var/db/scripts/commit
directory on the hard drive or the/config/scripts/commit
directory on the flash drive. For more information about script storage location, see Storing Scripts in Flash Memory. 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.
Commit the configuration:
[edit]user@host# commit
The commit script does not execute during this commit operation, but executes automatically during each subsequent commit operation.
Preventing Commit Scripts from Executing During Commit Operations
To prevent a commit script from executing during a commit operation, follow these steps:
- filename—Name of the commit script.
Delete the commit script filename at the [edit system scripts commit] hierarchy level:
[edit system scripts commit]user@host# delete file filename - Remove the commit script from the commit script directory. Although removing the commit script from the commit script directory is not necessary, it is always a good policy to delete unused files from the system.
Commit your changes:
[edit]user@host# commit
Deactivating Commit Scripts
To deactivate a commit script, follow these steps:
Issue the deactivate command:
[edit]user@host# deactivate system scripts commit file filenameCommit your changes:
[edit]user@host# commit
A deactivated commit script is marked as inactive: and ignored during a commit operation.
In this example, the script mycommit.slax
is deactivated:
Activating Commit Scripts
To activate an inactive commit script, follow these steps:
Issue the activate command:
[edit]user@host# activate system scripts commit file filenameCommit your changes:
[edit]user@host# commit
The commit script does not execute during this commit operation, but executes automatically during each subsequent commit operation.