To change the configuration use the jcs:load-configuration template. This template is included in the junos.xsl default import file and is available for use by all op scripts (in Junos 9.3 and later). Before using jcs:load-configuration a connection must be opened. This is needed because multiple steps must occur for a configuration change to be successful:
  1. The configuration database is locked
  2. The configuration changes are loaded
  3. The configuration is committed
  4. The configuration database is unlocked

All of these actions must be performed in a sequence with no interference from other users or scripts. Junos uses connections to ensure that the steps are performed together rather than in isolation. These connections are first created by the jcs:open() function, which returns a connection identifier. When the script is ready to make a configuration change it passes this connection to the jcs:load-configuration template. After the changes have been completed, the connection should be closed by using the jcs:close() function.

version 1.0;

ns junos = "*/junos";
ns xnm = "";
ns jcs = "";

import "../import/junos.xsl";

match / {
    /* The configuration change must be defined */
    var $configuration-change = <configuration> {
        <routing-options> {
            <static> {
                <route> {
                    <name> "";
                    <next-hop> "";
    /* A connection must be opened */
    var $connection = jcs:open();

    * The connection and change are set as parameters to the jcs:load-configuration
    * template which performs the change. The := operator is used to ensure that the
    * $results variable is a node-set rather than a result tree fragment.
    var $results := { call jcs:load-configuration( $connection, $configuration = $configuration-change ); }
    /* Check for errors – report them if they occurred */
    if( $results//xnm:error ) {
        for-each( $results//xnm:error ) {
            <output> message;
    /* The connection is closed */
    var $close-results = jcs:close($connection);