Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation
 

Related Documentation

 

Declaring Arguments in Op Scripts

There are two ways to declare arguments to an op script: by including XSLT or SLAX instructions in the script or by including statements in the Junos configuration. Script-generated and configuration-generated arguments have the same operational impact.

To declare arguments within a script, declare a global variable named arguments, containing <argument> tag elements. Within each <argument> tag element, include the required <name> tag element and the optional <description> tag element:

XSLT Syntax

<xsl:variable name="arguments">
    <argument>
        <name>name</name>
        <description>name</description>
    </argument>
</xsl:variable>

SLAX Syntax

var $arguments = {
    <argument> {
        <name> "name";
        <description> "descriptive-text";
    }
}

To declare arguments in the configuration, include the arguments statement in the [edit system scripts op file filename] hierarchy level.

[edit system scripts op file filename]
arguments {argument-name {description descriptive-text;}}

If you include the optional <description> tag element or the description statement, the text of the description appears in the command-line interface (CLI) as a help-text string to describe the purpose of the argument, as discussed in Configuring Help Text for Op Scripts.

In the operation script, you must include a corresponding parameter declaration for each argument. The parameter name must match the name of the argument:

<xsl:param name="name"/>

The SLAX equivalent is:

param $name;

You can create a hidden argument by including the <xsl:param name="name"/> instruction without listing the argument in the arguments variable or in the configuration.

After you declare an argument, you can use command completion to list available arguments:

user@host> op filename ?
Possible completions:
argument-name        description
argument-name        description

For each argument you include on the command-line, you must specify a corresponding value. To do this, include an argument-name and an argument-value when you execute the script with the op filename command:

user@host> op filename argument-name argument-value

Note: If you specify an argument that the script does not recognize, the script ignores the argument.

If you configure arguments by including the arguments statement in the configuration, any arguments that you declare directly in the script are still available, but are not listed among the Possible completions when you issue the op filename ? command.

If you declare all arguments in the script (and none in the configuration), then the arguments do appear in the Possible completions list. This is because the management (mgd) process populates the Possible completions list by first checking the configuration for arguments. The mgd process looks in the script for arguments only if no arguments are found in the configuration. Thus, if arguments are declared in the configuration, the arguments declared in the script become hidden in the CLI.

Example: Declaring Arguments

Declare two arguments named interface and protocol. Execute the script, specifying the ge-0/2/0.0 interface and the inet protocol as values for the arguments. For either method, you must declare corresponding script parameters:

<xsl:param name="interface"/>
<xsl:param name="protocol"/>

Declaring Arguments in the Op Script (script1)

<xsl:variable name="arguments">
    <argument>
        <name>interface</name>
        <description>Name of interface to display</description>
    </argument>
    <argument>
        <name>protocol</name>
        <description>Protocol to display (inet, inet6)</description>
    </argument>
</xsl:variable>

Declaring Arguments in the Configuration

[edit system scripts op]
file script1 {arguments {interface {description "Name of interface to display";}protocol {description "Protocol to display (inet, inet6)";}}}

Executing the Script

user@host> op script1 interface ge-0/2/0.0 protocol inet
 

Related Documentation

 

Published: 2013-03-05

 

Related Documentation

 

Published: 2013-03-05