Usage of the output filter on Juniper CLI

You may have seen in the previous lessons that whenever we want to check if the configuration is done correctly then we use the “show” command.

In this lesson, I will explain how you can filter the output of the “show” command.

I am still connected via a console cable to the Juniper router. Let me show you how you can filter the “show” command:

root# show | ?

Possible completions:

append              Append output text to file

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

save                Save output text to file

tee                  Write to standard output and file

trim                 Trim specified number of columns from start of line

When I write “show” with a pipe and a question mark, it shows for me the output filters that I can use.

The 1st output filter that I want to speak about is the “count”. When you write just “show”, it will show you the configuration on the router via lines as the following:

root# show

## Last changed: 2024-02-03 17:39:40 UTC

version 14.1R4.8;

system {

root-authentication {

encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”; ## SECRET-DATA

}

syslog {

user * {

any emergency;

}

file messages {

any notice;

authorization info;

}

file interactive-commands {

interactive-commands any;

}

}

}

 

[edit]

root#

I will use the output filter “count” and see what I will get:

root# show | count

Count: 19 lines

[edit]

root#

It will count how many lines does the “show” command has as an output, and in my case there are 19 lines (you can count them if you want by going back to the output of the “show” command).

The other output filter that I want to speak about is the “display set”. When we did “show” command, we have received the output of the configuration on the Juniper router in a programming way. Say that you wish to copy the same configuration from this router to another router, then you can use the “display set” output filter and you will be able to copy the output of this command to another router. Let me show you how you can do it:

root# show | display set

set version 14.1R4.8

set system root-authentication encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”

set system syslog user * any emergency

set system syslog file messages any notice

set system syslog file messages authorization info

set system syslog file interactive-commands interactive-commands any

[edit]

root#

Of course I don’t have many configuration yet on the router, but as you see the output is the same as on the “show” command but not as a programming way and I have the “set” command behind each line so copying the output to another router will work directly.

The other output filter that I want to speak about is the “save”. When you use this output filter with the “show” command, then you can save the output of the “show” is a file.

Let’s try it:

root# show | save ?

Possible completions:

<filename>           Output file name (or URL)

I will save the configuration on a file called “Config2”:

root# show | save Config2

Wrote 19 lines of output to ‘Config2’

[edit]

root#

Very good, this has been saved. For curiosity, I want to check the content of the “Config2” file. Remember, we have to go to the shell mode and check it from there:

root# quit

Exiting configuration mode

root> quit

root@% ls

.cshrc          .history        .login          .profile        Config2

root@%

I can clearly see the file is there. Let’s open it and see the content:

root@% cat Config2

## Last changed: 2024-02-03 17:39:40 UTC

version 14.1R4.8;

system {

root-authentication {

encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”; ## SECRET-DATA

}

syslog {

user * {

any emergency;

}

file messages {

any notice;

authorization info;

}

file interactive-commands {

interactive-commands any;

}

}

}

root@%

It contains the same configuration that is on the router 😊

The other output filter that I want to speak about is the “Compare”. With this, you can compare your current configuration with another saved configuration. To show you this, I will add a user on the Juniper router then I will compare the current configuration with the Config2 file that I have created it previously to see if it will tell me that there was a new user created. Let’s do it:

root@% cli

root> edit

Entering configuration mode

 

[edit]

root# set system login user Maher authentication plain-text-password

New password:

Retype new password:

root# set system login user Maher class super-user

[edit]

root# commit

commit complete

[edit]

root#

Now I have create a user called Maher, gave it a super-user permissions and saved the configuration. Let’s do the comparison now between the 2 configurations:

root# show | compare Config2

[edit system]

+   login {

+       user Maher {

+           uid 2001;

+           class super-user;

+           authentication {

+               encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”; ## SECRET-DATA

+           }

+       }

+   }

[edit]

root#

You can see that at the beginning of each line there is the plus sign (+) meaning that those commands for user Maher has been added compared to the old configuration that is saved on the “Config2” file.

Another output filter that I like to show you is the “except”. Using it, you can say that you want to see the output of the show command except something that you don’t want to see. Let’s issue a “show | display set” again and see what we would like to not see when we use “except” command:

root# show | display set

set version 14.1R4.8

set system root-authentication encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”

set system login user Maher uid 2001

set system login user Maher class super-user

set system login user Maher authentication encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”

set system syslog user * any emergency

set system syslog file messages any notice

set system syslog file messages authorization info

set system syslog file interactive-commands interactive-commands any

[edit]

root#

Very good. Let’s say I want to repeat this command but I do not want to see anything related to the user. Let’s try it:

root# show | display set | except user

set version 14.1R4.8

set system root-authentication encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”

set system syslog file messages any notice

set system syslog file messages authorization info

set system syslog file interactive-commands interactive-commands any

[edit]

root#

You can see, everything related to the user pattern has been removed from the output 😊

The other output filter is the “match”. It is in fact the contrary of the “except” that we have just seen it. With “match”, you say you only need to see the pattern that you indicate. For example, I want to see from the show command only the part related to the user pattern. Let’s check that again:

root# show | display set | match user

set system login user Maher uid 2001

set system login user Maher class super-user

set system login user Maher authentication encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”

set system syslog user * any emergency

[edit]

root#

I only got the output for everything related to the user pattern.

Another output filter is “find”. With this command, the Juniper router will show you everything related to the pattern that you have written. For example, if I use again the pattern user, then the router will show me everything related to the user pattern. Let’s try it and see:

root# show | display set | find user

set system login user Maher uid 2001

set system login user Maher class super-user

set system login user Maher authentication encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”

set system syslog user * any emergency

set system syslog file messages any notice

set system syslog file messages authorization info

set system syslog file interactive-commands interactive-commands any

As I have mentioned, everything related to user pattern was shown including the system syslog’s.

Another output filter is “last”. If you have a big output of many pages, when you use the “last” command it will show you only the last page of the output.

If I write now just show, it will show me 2 pages as the following:

root# show

## Last changed: 2024-02-03 18:08:55 UTC

version 14.1R4.8;

system {

root-authentication {

encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”; ## SECRET-DATA

}

login {

user Maher {

uid 2001;

class super-user;

authentication {

encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”; ## SECRET-DATA

}

}

}

syslog {

user * {

any emergency;

}

file messages {

any notice;

authorization info;

—(more)—

}

file interactive-commands {

interactive-commands any;

}

}

}

 

[edit]

root#

Let’s use the “last” output filter and see if it will just show me the last page:

root# show | last

login {

user Maher {

uid 2001;

class super-user;

authentication {

encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”; ## SECRET-DATA

}

}

}

syslog {

user * {

any emergency;

}

file messages {

any notice;

authorization info;

}

file interactive-commands {

interactive-commands any;

}

}

}

—(more 100%)—

Indeed, it has showed me the last page only of the show command.

The last output filter that I want to discuss about is “no-more”. As you already now know, when you do show and you got a big output, the Juniper router divides them into pages and you need to press on space on the keyboard to load the upcoming page. When you say “no-more” then all the output will show in just 1 page:

root# show | no-more

## Last changed: 2024-02-03 18:08:55 UTC

version 14.1R4.8;

system {

root-authentication {

encrypted-password “$1$3hHX87WB$VlIPrcgAMz9TInBYol9.U/”; ## SECRET-DATA

}

login {

user Maher {

uid 2001;

class super-user;

authentication {

encrypted-password “$1$UPyfh6tA$1Wa78MgVEsAZf/jUqxPVY0”; ## SECRET-DATA

}

}

}

syslog {

user * {

any emergency;

}

file messages {

any notice;

authorization info;

}

file interactive-commands {

interactive-commands any;

}

}

}

 

[edit]

root#

Everything is loaded into one page.

This is all what I wanted to explain in this lesson, I hope you enjoyed it and see you in the upcoming one 😊

Course Content

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

About