12 12
发新话题
打印

[网络转载] JUNOS PIPE 参数总结

JUNOS PIPE 参数总结

无论在Operational模式还是在Configuration模式下面,对于输出相关信息的命令,譬如

show/help,我们都可以在输入命令以后,使用PIPE(|)符号对输出的信息进行过滤。常见的可

选项为:

root> show configuration | ?
Possible completions:
compare          Compare configuration changes with prior version
count          Count occurrences
display          Show additional kinds of information
except          Show only text that does not match a pattern
find          Search for first occurrence of pattern
hold          Hold text without exiting the --More-- prompt
last          Display end of output only
match          Show only text that matches a pattern
no-more          Don't paginate output
request          Make system-level requests
resolve          Resolve IP addresses
save          Save output text to file
trim          Trim specified number of columns from start of line

======================================
以下我们逐一对每项参数进行归纳总结:
======================================

Compare ——

compare 用于使用当前【Candidate】配置与:当前【Committed】配置(Rollback 1);之前

committed 的50个配置文件;或者任意一个之前保存下来的配置文件进行比较。

命令格式:
------------------------------------------------
[edit]

user@host# show | compare [ 文件名 | rollback n]
------------------------------------------------

文件名:这个参数默认是路径是相关用户的home目录(/var/home/用户名)。假如你需要与保存

在其它地方的配置文件进行对比,那么我们需要的是指定该配置文件在FreeBSD底下的完整路径。

n:这个参数定义的是之前所保存的50个已被committed 的配置文件中的序号。

假如你在compare后面不加入任何参数,那么系统JUNOS将使用【Candidate】配置与内置flash当

中的config/juniper.conf 配置文件进行比较。PS:对于Olive而言,由于没有所谓

PCMIC/Compact Flash的概念,本来应该存放在Compact Flash 中的config 目录被安装在FreeBSD

的根目录下面。—— juniper.conf 实际上就是rollback 1.

比较后的输出采用以下方式标识:

* 仅在【Candidate】配置下添加的配置;将使用加号标识(+).
* 仅在相关对比文件中存在的配置,或者是在【Candidate】配置中被删除的配置;将使用减号标

识(-).
* 没有被修改的配置;将使用空格标识( ).

例:

user@host> show configuration system | compare rollback 9
[edit system]
+ host-name nutmeg;
+ backup-router 192.168.71.254;
- ports {
-     console log-out-on-disconnect;
- }
[edit system name-server]
+ 172.17.28.11;
   172.17.28.101 { ... }
[edit system name-server]
   172.17.28.101 { ... }
+ 172.17.28.100;
+ 172.17.28.10;
[edit system]
- scripts {
-      commit {
-          allow-transients;
-      }
- }
+ services {
+      ftp;
+      rlogin;
+      rsh;
+      telnet;
+ }

======================================

Count ——

用于统计输出信息条目数量。

例:

user@host> show configuration | count
Count: 269 lines

======================================

Display ——

该参数后面紧跟着好几个子参数,分别为:

------------------------------------------------
* Detail:根据不同的命令或者JUNOS版本,用于显示更为详尽的信息,并且对每一段输出给予相

关的解析。如(以##为前缀的信息为解析信息;其它则为实际配置):

root# show system | display detail
##
## system: System parameters
## require: admin system
##
##
## login: Names, login classes, and passwords for users
## require: admin
##
login {
    ##
    ## message: System login message
    ## range: 1 .. 2048
    ##
    message "This is an Olive";
    ##
    ## User name (login)
    ## match: Must be 1 to 16 characters (alphanumerics, underscores or hypens)

starting with a non-hypen character
    ## match (regex): ^[[:alnum:]_][[:alnum:]_-]{1,15}$
    ##
    user nigel {
        ##
        ## uid: User identifier (uid)
        ## range: 100 .. 64000
        ##
        uid 2005;
        ##
        ## class: Login class
        ## match (regex): ^[[:alnum:]_-]+$
        ##
        class superuser;
        ##
        ## authentication: Authentication method
        ##
        authentication {
            ##
            ## encrypted-password: Encrypted password string
            ##
            encrypted-password "$1$TlAYG0vx$XlobOj/wOC6BooaRyeUme."; # SECRET-DATA
        }
    }
}

[edit]
------------------------------------------------

* Inheritance:显示那些通过继承模式配置以及它们是通过哪个源配置组继承下来的。

------------------------------------------------

* Set:用于显示相关配置当时如何使用【set】命令被配置上去。
例:

root> show configuration system | display set
set system login message "This is an Olive"
set system login user nigel uid 2005
set system login user nigel class superuser
set system login user nigel authentication encrypted-password "$1

$TlAYG0vx$XlobOj/wOC6BooaRyeUme."

------------------------------------------------

* XML:使用这个参数,JUNOS将把输出的内容采用打上XML标签的格式输出。由于在2005-06年的

时候做了接近一年Web应用程序开发,一开始用的就是基于.NET2.0的Visual Studio,后来的php

,ruby on rails等那是后话了。因此对于XML这个参数特别感兴趣。XML代表Extensible Markup

Language(eXtensible Markup Language 的缩写,意为可扩展的标记语言)。我们还可以把XML

数据转换成其它格式,并用不同的视图来表示其内容。最简单的方法就是使用XSLT转换,它提供

了一种强大的面向树的转换语言实现,可以把使用一种词汇表的XML实例转换成简单文本、HTML或

者使用其它词汇表的XML.基于HTTP管理Juniper路由器的JWeb,实际上采用的便是将路由器里面采

用XML储存的配置及数据,通过Web Service将相关XML数据转换成为UI更为美观的HTTP格式,我们

便可以通过Web浏览器对路由器进行更为直观的管理。这里好像已经超出了网络工程师了解的范围

,如果有兴趣可以通过下面的URL,来对XML Web Service进行进一步的了解。

http://www.microsoft.com/china/net/xmlservices.mspx

下面是一个例子,尝试把它保存下来扩展名为【.xml】;然后用【Excel】打开看看?:D

root> show interfaces fxp0 | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/6.3R1/junos">
    <interface-information xmlns="http://xml.juniper.net/junos/6.3R1/junos-interface"

junos:style="normal">
        <physical-interface>
            <name>fxp0</name>
            <admin-status junos:format="Enabled">up</admin-status>
            <oper-status>up</oper-status>
            <local-index>1</local-index>
            <snmp-index>1</snmp-index>
            <if-type>Ethernet</if-type>
            <link-level-type>Ethernet</link-level-type>
            <mtu>1514</mtu>
            <speed>10m</speed>
            <if-device-flags>
               <ifdf-present/>
               <ifdf-running/>
            </if-device-flags>
            <if-config-flags>
               <iff-snmp-traps/>
            </if-config-flags>
            <link-type>Half-Duplex</link-type>
            <if-media-flags>
               <generic-value>4</generic-value>
            </if-media-flags>
            <current-physical-address junos:format="MAC

02:00:00:00:00:01">02:00:00:00:00:01</current-physical-address>
            <hardware-physical-address junos:format="MAC

02:00:00:00:00:01">02:00:00:00:00:01</hardware-physical-address>
            <interface-flapped junos:seconds="0">Never</interface-flapped>
            <traffic-statistics junos:style="brief">
               <input-packets>4</input-packets>
               <output-packets>1</output-packets>
            </traffic-statistics>
            <logical-interface>
               <name>fxp0.0</name>
               <local-index>74</local-index>
               <snmp-index>13</snmp-index>
               <if-config-flags>
                    <iff-snmp-traps/>
               </if-config-flags>
               <link-address junos:format="VLAN-Tag [ 0x8100.23 ] ">[ 0x8100.23 ]

</link-address>
               <encapsulation>ENET2</encapsulation>
               <traffic-statistics junos:style="brief">
                    <input-packets>0</input-packets>
                    <output-packets>1</output-packets>
               </traffic-statistics>
               <address-family>
                    <address-family-name>inet</address-family-name>
                    <mtu>1496</mtu>
                    <address-family-flags>
                        <ifff-is-primary/>
                    </address-family-flags>
                    <interface-address>
                        <ifa-flags>
                            <ifaf-current-default/>
                            <ifaf-current-preferred/>
                            <ifaf-current-primary/>
                        </ifa-flags>
                        <ifa-destination>10.1.23/24</ifa-destination>
                        <ifa-local>10.1.23.4</ifa-local>
                        <ifa-broadcast>10.1.23.255</ifa-broadcast>
                    </interface-address>
               </address-family>
            </logical-interface>
        </physical-interface>
    </interface-information>
    <cli>
        <banner></banner>
    </cli>           
</rpc-reply>

======================================

Expect ——

在显示结果中剔除掉包含某个字符或者通配符的那些行,如果我们所指定的字符或者通配符当中

包含了空格,那么我们需要用引号(Quotation Marks)将整段字符或者通配符涵盖在里面。

例:

------------------------------------------------

root> show interfaces fxp0
Physical interface: fxp0, Enabled, Physical link is Up
Interface index: 1, SNMP ifIndex: 1
Type: Ethernet, Link-level type: Ethernet, MTU: 1514, Speed: 10m
Device flags   : Present Running
Interface flags: SNMP-Traps
Link type      : Half-Duplex
Link flags     : 4
Current address: 02:00:00:00:00:01, Hardware address: 02:00:00:00:00:01
Last flapped   : Never
Input packets : 4
Output packets: 1

Logical interface fxp0.0 (Index 74) (SNMP ifIndex 13)
    Flags: SNMP-Traps VLAN-Tag [ 0x8100.23 ] Encapsulation: ENET2
Input packets : 0
Output packets: 1
    Protocol inet, MTU: 1496
      Flags: Is-Primary
      Addresses, Flags: Is-Default Is-Preferred Is-Primary
        Destination: 10.1.23/24, Local: 10.1.23.4, Broadcast: 10.1.23.255

------------------------------------------------

root> show interfaces fxp0 | except L
Interface index: 1, SNMP ifIndex: 1
Current address: 02:00:00:00:00:01, Hardware address: 02:00:00:00:00:01
Input packets : 4
Output packets: 1

Input packets : 0
Output packets: 1

======================================

Find ——

在显示结果中查找到指定的字符或者通配符后,才开始显示。同样,如果我们所指定的字符或者

通配符当中包含了空格,那么我们需要用引号(Quotation Marks)将整段字符或者通配符涵盖在

里面。

例1:

root> show interfaces fxp0 | find logical
Logical interface fxp0.0 (Index 74) (SNMP ifIndex 13)
    Flags: SNMP-Traps VLAN-Tag [ 0x8100.23 ] Encapsulation: ENET2
Input packets : 0
Output packets: 1
    Protocol inet, MTU: 1496
      Flags: Is-Primary
      Addresses, Flags: Is-Default Is-Preferred Is-Primary
        Destination: 10.1.23/24, Local: 10.1.23.4, Broadcast: 10.1.23.255

------------------------------------------------

例2:

user@host> show route | find 208.197.169.0

208.197.169.0/24   *[Static/5] 1d 13:22:11
                    > to 192.168.4.254 via so-3/0/0.0
224.0.0.5/32       *[OSPF/10] 1d 13:22:12, metric 1

iso.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

47.0005.80ff.f800.0000.0108.0001.1921.6800.4015.00/160
                   *[Direct/0] 1d 13:22:12
                    > via lo0.0

======================================

Hold ——

默认情况下面,当我们输入show/help等命令以后,JUNOS会直接将我们带回相关模式的提示符下

。而使用【hold】这个参数则在输出信息显示完成以后,JUNOS并不会马上返回到提示符模式底下

。而停留在【---(more 100%)---】下,等待我们敲入空格、回车、Ctrl+C键的时候才将我们带回

相关模式的提示符下。

======================================

Last n ——

n:只显示从最后开始倒数第n行的信息。

======================================

Match ——

与【Expect】正好相反,在显示结果中仅仅显示包含某个字符或者通配符的那些行,如果我们所

指定的字符或者通配符当中包含了空格,那么我们需要用引号(Quotation Marks)将整段字符或

者通配符涵盖在里面。

例:

root> show interfaces | match MTU
Type: Software-Pseudo, MTU: Unlimited
Type: Ethernet, Link-level type: Ethernet, MTU: 1514, Speed: 10m
    Protocol inet, MTU: 1496
Type: Ethernet, Link-level type: Ethernet, MTU: 1514, Speed: 10m
    Protocol inet, MTU: 1496
    Protocol inet, MTU: 1496
Type: Ethernet, Link-level type: Ethernet, MTU: 1514, Speed: 10m
    Protocol inet, MTU: 1496
    Protocol inet, MTU: 1496
Type: GRE, Link-level type: GRE, MTU: Unlimited, Speed: Unlimited
Type: IPIP, Link-level type: IP-over-IP, MTU: Unlimited, Speed: Unlimited
Type: Loopback, MTU: Unlimited
    Protocol inet, MTU: Unlimited
    Protocol inet6, MTU: Unlimited
Type: Software-Pseudo, Link-level type: LSI, MTU: 1496, Speed: Unlimited
Physical interface: mtun, Enabled, Physical link is Up
Type: Multicast-GRE, Link-level type: GRE, MTU: Unlimited, Speed: Unlimited
Type: PIMD, Link-level type: PIM-Decapsulator, MTU: Unlimited,
Type: PIME, Link-level type: PIM-Encapsulator, MTU: Unlimited,
Type: Software-Pseudo, Link-level type: Interface-Specific, MTU: Unlimited,

======================================

No-more ——

默认情况下,如果显示结果的长度大于终端屏幕,那么在显示完第一屏以后,我们会停留在【--

(-more)--- 】提示符下面;并且显示剩余显示信息的百分数【---(more 52%)---】。使用【no-

more】参数,显示结果将不会停留而从一开始一直显示到最后一屏。当我们需要做logging的时候

,将显示信息直接捕获到某个终端机文件上面的时候,这是一个不错的选择!

======================================

Request ——

JUNOS是一个允许多用户同时配置的系统,当存在多个工程师联调/排错同一台路由器的时候,我

们可以使用【request】参数,将输入信息直接通过系统发送给所有用户【request message all

】,或者是某个指定用户。

例:

user@host> show interfaces | request message user root@ttyp1

那么在这个时候,root@ttyp1将在他的终端屏幕上出现以下信息:

Message from user@host on /dev/ttyp0 at 10:32 PST...
Physical interface: dsc, Enabled, Physical link is Up
   Interface index: 5, SNMP ifIndex: 5
   Type: Software-Pseudo, MTU: Unlimited ...

另:我们可以使用【show system users】命令来查看当前登录用户。

======================================

Resolve ——

假如在输出信息中含有IP地址,当你希望将这些IP地址解析为主机名字的时候,可以使【resolve

】这个参数。路由器会使用反向DNS查询相关IP地址的主机/域名,当然,前提是你必须配置好相

关的DNS服务器。否则该命令将失效!

======================================

Save ——

输出信息并非显示在终端屏幕上面,而是被保存在一个你指定文件名的文件当中。日后你也可以

使用【file show】命令将之前保存的输出信息从相关文件当中调用显示到终端屏幕上面。另外假

如你打开路由器上的FTP服务的话,也可以将文件下载回自己的PC上查看。

======================================

Trim ——

这个参数到目前为止还没有想得到合适的使用情景?【trim】后面的参数【n】用于指定在显示信

息出来的时候屏蔽掉前面n列的信息。

例:

root> show system storage
Filesystem        512-blocks       Used      Avail Capacity Mounted on
/dev/ad0s1a           218690      68356     132840     34% /
devfs                     32        32          0    100% /dev/
/dev/vn0               22816      22816          0    100% /packages/mnt/jbase
/dev/vn1               77956      77956          0    100% /packages/mnt/jkernel-

6.3R1.3
/dev/vn2               22852      22852          0    100% /packages/mnt/jpfe-M40-

6.3R1.3
/dev/vn3               4492       4492          0    100% /packages/mnt/jdocs-

6.3R1.3
/dev/vn4               27556      27556          0    100% /packages/mnt/jroute-

6.3R1.3
/dev/vn5               9620       9620          0    100% /packages/mnt/jcrypto-

6.3R1.3
mfs:152               609422          2     560668      0% /tmp
/dev/ad0s1e            24234        18      22278      0% /config
procfs                     8          8          0    100% /proc
/dev/ad0s1f          1585646     398080    1060716     27% /var

------------------------------------------------

root> show system storage | trim 50
Capacity Mounted on
     34% /
    100% /dev/
    100% /packages/mnt/jbase
    100% /packages/mnt/jkernel-6.3R1.3
    100% /packages/mnt/jpfe-M40-6.3R1.3
    100% /packages/mnt/jdocs-6.3R1.3
    100% /packages/mnt/jroute-6.3R1.3
    100% /packages/mnt/jcrypto-6.3R1.3
      0% /tmp
      0% /config
    100% /proc
     27% /var

======================================

【终极TIPS】:Pipe最为强悍之处在于当我们熟练掌握各个参数的作用之后,我们甚至可以采用

多个Pipe重叠的方式对输出结果进行多重过滤及操作!!!想像一下某厂家的操作系统能做到这

样的一点吗 ——

lab@hongkong> show route logical-router r1 |except 192.168|last 20|trim 20

[MPLS/0] 00:11:38, metric 1
Receive
[MPLS/0] 00:11:38, metric 1
Receive
[MPLS/0] 00:11:38, metric 1
Receive
[LDP/9] 00:11:09, metric 1
> to 20.12.33.2 via fxp1.67, Pop      
[LDP/9] 00:11:09, metric 1
> to 20.12.33.2 via fxp1.67, Pop      
[LDP/9] 00:10:51, metric 1
> to 20.12.33.2 via fxp1.67, Swap 100000
[LDP/9] 00:10:41, metric 1
> to 20.12.33.2 via fxp1.67, Swap 100016
[LDP/9] 00:10:36, metric 1
> to 20.12.33.2 via fxp1.67, Swap 100032
[LDP/9] 00:10:36, metric 1
> to 20.12.33.2 via fxp1.67, Swap 100048
[LDP/9] 00:10:32, metric 1
> to 20.12.33.2 via fxp1.67, Swap 100064
[LDP/9] 00:10:31, metric 1
> to 20.12.33.2 via fxp1.67, Swap 100080

TOP

goooooooooooooooooooooooooooooooooooooooood

TOP

up up up up?<;+enu:":

TOP

www.24327539.com东方机械立式烤鸭炉全国批发供应立式烤鸭炉厂家

提示: 作者被禁止或删除 内容自动屏蔽

TOP

 12 12
发新话题