Piping show commands

      2 Comments on Piping show commands

Piping commands is an excellent way to limit or redirect the output of a show command.  For me, it was one of the things I always knew about but just never got in the practice of doing.  Here are some examples:

Edit: I wasn’t very clear on what ‘piping’ meant.  Piping refers to the use of the | symbol.  The | is located above the enter key on most keyboards and since it looks like a pipe, we call it ‘piping’.

Notes
-Insert your relevant information between <>
-Console prompts are show in green
-Text in blue are variable names I made up, feel free to change them

Exclude
Notes: We use the exclude command here to remove all of the interfaces that don’t have IP addresses assigned to them.  That’s the best (and only) example I can think of for using exclude

Cisco2801# show ip int brief | exclude unassigned
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0.1          10.20.30.1      YES NVRAM  up                    up
FastEthernet0/0.2          10.10.10.1      YES NVRAM  up                    up
FastEthernet0/1            172.172.172.1   YES NVRAM  up                    up

Include
Notes: We use the include command here to limit the output from the ‘show processes cpu’ command.  This command normally returns a few screens worth of data.  Here we only show the output for lines including the work ‘Chunk’.  Note that the include is case sensitive.  That is, if I specify ‘Chunk’ I get the Chunk Manager line.  But if I specify ‘chunk’ I get the ‘TurboACL chunk’ line.  This is shown in the example output below.

Cisco2801# show processes cpu | include Chunk
   1           0        46          0  0.00%  0.00%  0.00%   0 Chunk Manager
Cisco2801# show processes cpu | include chunk
  69           0         2          0  0.00%  0.00%  0.00%   0 TurboACL chunk

Begin
Notes: The begin command can be used to select where you want to ‘begin’ the console output of your show command.  For instance, in the example below I want to start the output of the ‘show run’ command at statically defined routes.  This is similar to on the ASA appliances where you are able to issues the command ‘show run route’ which will only output the route commands. 

Cisco2801# show run | begin ip route
ip route 0.0.0.0 0.0.0.0 172.172.172.2
ip route 192.168.17.0 255.255.255.0 172.172.172.2
!

Redirect
Notes: Say we want to redirect the output of a show command to a TFTP server.  This can be done by using the redirect command.  The example below shows the redirection of the ‘show ip int brief’ command to a file on my TFTP server.

Cisco2801#show ip int brief | redirect tftp://<TFTP Server IP>/MyRedirect
!

Screenshot of the output in a text editor.
image

Append
Notes: Same deal as redirect but you can append the output to an existing file.  Let’s append the output of the ‘show ip route’ command to the same file so you can see what it looks like.  Note that append to an external source isn’t supported on all routers.  You may get a ‘% Appending is not supported in this file system’ when you try to append which indicates your router does not support random writes.

Cisco2801# show ip route | append tftp://<TFTP Server IP>/MyRedirect

image

Tee
Notes: Not exactly sure when you NEED to use this but if you want to output the file to a TFTP server as well as see it on the screen you can use the ‘tee’ command.  Example below.  The exclamation point shows that it was sent to the TFTP server and the actual output is shown below.

Cisco2801# show ip route | tee tftp://10.20.30.52/MyRedirect3
!
Codes: C – connected, S – static, R – RIP, M – mobile, B – BGP
       D – EIGRP, EX – EIGRP external, O – OSPF, IA – OSPF inter area
       N1 – OSPF NSSA external type 1, N2 – OSPF NSSA external type 2
       E1 – OSPF external type 1, E2 – OSPF external type 2
       i – IS-IS, su – IS-IS summary, L1 – IS-IS level-1, L2 – IS-IS level-2
       ia – IS-IS inter area, * – candidate default, U – per-user static route
       o – ODR, P – periodic downloaded static route

Gateway of last resort is 172.172.172.2 to network 0.0.0.0

     172.172.0.0/30 is subnetted, 1 subnets
C       172.172.172.0 is directly connected, FastEthernet0/1
     10.0.0.0/24 is subnetted, 2 subnets
C       10.20.30.0 is directly connected, FastEthernet0/0.1
C       10.10.10.0 is directly connected, FastEthernet0/0.2
S    192.168.17.0/24 [1/0] via 172.172.172.2
S*   0.0.0.0/0 [1/0] via 172.172.172.2

Conclusion
All in all, some (if not all) of these commands can come in handy.  I find myself doing piping all of the time now!

2 thoughts on “Piping show commands

  1. wjm

    This is my favorite “| exclude” use.

    show processes cpu | exclude 0.00% 0.00% 0.00%

    It really cuts down on looking at processes.

    Reply

Leave a Reply to wjm Cancel reply

Your email address will not be published.