By default, the layout of the show interfaces terse command looks like this:
user@host> show interfaces terse
Interface Admin Link Proto Local Remote
dsc up up
fxp0 up up
fxp0.0 up up inet 192.168.71.246/21
fxp1 up up
fxp1.0 up up inet 10.0.0.4/8
inet6 fe80::200:ff:fe00:4/64
fec0::10:0:0:4/64
tnp 4
gre up up
ipip up up
lo0 up up
lo0.0 up up inet 127.0.0.1 --> 0/0
lo0.16385 up up inet
inet6 fe80::2a0:a5ff:fe12:2f04
lsi up up
mtun up up
pimd up up
pime up up
tap up up
In JUNOS XML, the output fields are represented as follows:
user@host> show interfaces terse | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/7.6I0/junos">
<interface-information xmlns="http://xml.juniper.net/junos/7.6I0/junos-interface" junos:style="terse">
<physical-interface>
<name>dsc</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
</physical-interface>
<physical-interface>
<name>fxp0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<logical-interface>
<name>fxp0.0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
...
(Output truncated)
XSLT Syntax
The following script customizes the output of the show interfaces terse command.
1 <?xml version="1.0" standalone="yes"?>
2 <xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:junos="http://xml.juniper.net/junos/*/junos"
5 xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
6 xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">
7 <xsl:import href="../import/junos.xsl"/>
8 <xsl:variable name="arguments">
9 <argument>
10 <name>interface</name>
11 <description>Name of interface to display</description>
12 </argument>
13 <argument>
14 <name>protocol</name>
15 <description>Protocol to display (inet, inet6)</description>
16 </argument>
17 </xsl:variable>
18 <xsl:param name="interface"/>
19 <xsl:param name="protocol"/>
20 <xsl:template match="/">
21 <op-script-results>
22 <xsl:variable name="rpc">
23 <get-interface-information>
24 <terse/>
25 <xsl:if test="$interface">
26 <interface-name>
27 <xsl:value-of select="$interface"/>
28 </interface-name>
29 </xsl:if>
30 </get-interface-information>
31 </xsl:variable>
32 <xsl:variable name="out" select="jcs:invoke($rpc)"/>
33 <interface-information junos:style="terse">
34 <xsl:choose>
35 <xsl:when test="$protocol='inet' or $protocol='inet6'
or $protocol='mpls' or $protocol='tnp'">
36 <xsl:for-each select="$out/physical-interface/
logical-interface[address-family/address-family-name = $protocol]">
37 <xsl:call-template name="intf"/>
38 </xsl:for-each>
39 </xsl:when>
40 <xsl:when test="$protocol">
41 <xnm:error>
42 <message>
43 <xsl:text>invalid protocol: </xsl:text>
44 <xsl:value-of select="$protocol"/>
45 </message>
46 </xnm:error>
47 </xsl:when>
48 <xsl:otherwise>
49 <xsl:for-each select="$out/physical-interface/logical-interface">
50 <xsl:call-template name="intf"/>
51 </xsl:for-each>
52 </xsl:otherwise>
53 </xsl:choose>
54 </interface-information>
55 </op-script-results>
56 </xsl:template>
57 <xsl:template name="intf">
58 <xsl:variable name="status">
59 <xsl:choose>
60 <xsl:when test="admin-status='up' and oper-status='up'">
61 <xsl:text> </xsl:text>
62 </xsl:when>
63 <xsl:when test="admin-status='down'">
64 <xsl:text>offline</xsl:text>
65 </xsl:when>
66 <xsl:when test="oper-status='down' and ../admin-status='down'">
67 <xsl:text>p-offline</xsl:text>
68 </xsl:when>
69 <xsl:when test="oper-status='down' and ../oper-status='down'">
70 <xsl:text>p-down</xsl:text>
71 </xsl:when>
72 <xsl:when test="oper-status='down'">
73 <xsl:text>down</xsl:text>
74 </xsl:when>
75 <xsl:otherwise>
76 <xsl:value-of select="concat(oper-status, '/', admin-status)"/>
77 </xsl:otherwise>
78 </xsl:choose>
79 </xsl:variable>
80 <xsl:variable name="desc">
81 <xsl:choose>
82 <xsl:when test="description">
83 <xsl:value-of select="description"/>
84 </xsl:when>
85 <xsl:when test="../description">
86 <xsl:value-of select="../description"/>
87 </xsl:when>
88 </xsl:choose>
89 </xsl:variable>
90 <logical-interface>
91 <name><xsl:value-of select="name"/></name>
92 <xsl:if test="string-length($desc)">
93 <admin-status><xsl:value-of select="$desc"/></admin-status>
94 </xsl:if>
95 <admin-status><xsl:value-of select="$status"/></admin-status>
96 <xsl:choose>
97 <xsl:when test="$protocol">
98 <xsl:copy-of
select="address-family[address-family-name = $protocol]"/>
99 </xsl:when>
100 <xsl:otherwise>
101 <xsl:copy-of select="address-family"/>
102 </xsl:otherwise>
103 </xsl:choose>
104 </logical-interface>
105 </xsl:template>
106 </xsl:stylesheet>