Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Display DNS Hostname Information Using an Op Script

This example uses an op script to display Domain Name System (DNS) information for a device in your network.

Requirements

This example uses a device running Junos OS.

Overview and Op Script

This script displays DNS information for a device in your network. The script offers a slight improvement over the show host hostname command because you do not need to enter a hostname or IP address to view DNS information for the device you are currently using.

There is no Junos Extensible Markup Language (XML) equivalent for the show host hostname command. Therefore, this script uses the show host hostname command directly rather than using a remote procedure call (RPC).

The script is provided in two distinct versions, one using the <xsl:choose> element and the other using the jcs:first-of() function. Both versions accept the same argument and produce the same output. Each version is shown in both XSLT and SLAX syntax.

XSLT Syntax Using the <xsl:choose> Element

XSLT Syntax Using the jcs:first-of() Function

SLAX Syntax Using the <xsl:choose> Element

SLAX Syntax Using the jcs:first-of() Function

Configuration

Procedure

Step-by-Step Procedure

To download, enable, and test the script:

  1. Copy the XSLT or SLAX script into a text file, name the file hostname.xsl or hostname.slax as appropriate, and copy it to the /var/db/scripts/op/ directory on the device.

  2. In configuration mode, include the file statement at the [edit system scripts op] hierarchy level and hostname.xsl or hostname.slax as appropriate.

  3. Issue the commit and-quit command to commit the configuration and to return to operational mode.

  4. Execute the op script by issuing the op hostname <dns (hostname | address)> operational mode command.

Verification

Verifying the Op Script Execution

Purpose

Verify that the script behaves as expected.

Action

When you issue the op hostname operational mode command without the dns option, DNS information is displayed for the local device:

When you issue the op hostname dns hostname command, DNS information is displayed for the specified device:

When you issue the op hostname dns address command, DNS information is displayed for the specified address: