Shell Scripting For Network Engineers
Shell Scripting For Network Engineers
This chapter describes techniques for using the command-line interface (CLI) of the
Cisco IOS XR software.
Contents
CLI Tips and Shortcuts, page 6-139
Displaying System Information with show Commands, page 6-144
Wildcards, Templates, and Aliases, page 6-155
Command History, page 6-160
Key Combinations, page 6-162
Note Commands can be entered in uppercase, lowercase, or mixed case. Only passwords are case sensitive.
However, the Cisco Systems documentation convention presents commands in lowercase.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-139
Chapter 6 CLI Tips, Techniques, and Shortcuts
CLI Tips and Shortcuts
Tip The space (or no space) before the question mark (?) is significant. If you include a space before the
question mark, the system displays all available options for a command or CLI mode. If you do not
include a space, the system displays a list of commands that begin with a particular character string.
Command Description
partial-command ? Enter a question mark (?) at the end of a partial command to list the commands that begin with those
characters.
RP/0/RP0/CPU0:router# co?
configure copy
Note Do not include a space between the command and question mark.
? Lists all commands available for a particular command mode.
command ? Include a space before the question mark (?) to list the keywords and arguments that belong to a
command.
RP/0/RP0/CPU0:router# configure ?
Note For most commands, the <cr> symbol indicates that you can execute the command with the
syntax already entered. For the preceding example, press Return to enter global configuration
mode.
command keyword ? Enter a question mark (?) after the keyword to list the next available syntax option for the command.
RP/0/RP0/CPU0:router# show aaa ?
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-140 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
CLI Tips and Shortcuts
The following example shows how to add an entry to access list 99. The added entry denies access to all
hosts on subnet 172.0.0.0 and ignores bits for IPv4 addresses that start within the range of 0 to 255. The
following steps provide an example of on-screen command help:
Step 1 Enter the access-list command, followed by a space and a question mark, to list the available options for
the command:
RP/0/RP0/CPU0:router(config)# ipv4 access-list ?
Note The number ranges (within the angle brackets) are inclusive ranges.
Step 2 Enter the access list name list1, followed by a space and another question mark, to display the arguments
that apply to the keyword and brief explanations:
RP/0/RP0/CPU0:router(config)# ipv4 access-list list1 ?
Step 3 Enter the deny option and a question mark to see more command options:
RP/0/RP0/CPU0:router(config)#ipv4 access-list list1 deny ?
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-141
Chapter 6 CLI Tips, Techniques, and Shortcuts
CLI Tips and Shortcuts
Step 4 Enter an IP address, followed by a space and a question mark (?), to list additional options:
RP/0/RP0/CPU0:router(config)# ipv4 access-list list1 deny 172.31.134.0 ?
The <cr> symbol by itself indicates that there are no more keywords or arguments.
Step 5 Press Enter to execute the command:
RP/0/RP0/CPU0:router(config)# ipv4 access-list list1 deny 172.31.134.0
Note The configuration does not become active until you enter the commit command to add the target
configuration to the running configuration.
The CLI displays the full command name. You must then press Return to execute the command. This
feature allows you to modify or reject the suggested command.
In the next example, the CLI recognizes two commands that match the text entered:
RP/0/RP1/CPU0:router# co<Tab>
configure copy
RP/0/RP1/CPU0:router# con<Tab>
RP/0/RP1/CPU0:router# configure
Tip If your keyboard does not have a Tab key, press Ctrl-I instead.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-142 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
CLI Tips and Shortcuts
Note The percent sign (%) indicates the line in which the error message occurred.
To display the correct command syntax, enter the ? after the command:
RP/0/RP0/CPU0:router# configure ?
In the next example, Ctrl-A is used to display the beginning of the command line, and the dollar sign at
the end of the command line shows the command has been scrolled to the right and the end of the
command is hidden.
RP/0/RP0/CPU0:router(config)# ipv4 access-list 101 permit tcp 172.31.134.5 255.255.255.0
17$
In the next example, the Right Arrow key has been used to scroll to the right. Notice that dollar sign
symbols appear at both ends of the line, which indicates that command information is hidden from the
beginning and end of the command.
RP/0/RP0/CPU0:router(config)# $ccess-list 101 permit tcp 172.31.134.5 255.255.255.0
172.31.$
By default, the Cisco IOS XR software uses a terminal screen 80 columns wide. To adjust for a different
screen width, use the terminal width command in EXEC mode.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-143
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
Use line wrapping with the command history feature to recall and modify previous complex command
entries.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-144 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
For more information on the use of these commands, see the Related Documents section on page x.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-145
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
Tip If you do not see the --More-- prompt, try entering a value for the screen length with the terminal
length command in EXEC mode. Command output is not paused if the length value is set to zero. The
following example shows how to set the terminal length:
For information on searching or filtering CLI output, see the Filtering show Command Output section
on page 6-148.
This feature enables you to save any of the show command output in a file for further analysis and
reference. When you choose to redirect command output, consider the following guidelines:
If the full path of the file is not specified, the default directory for your account is used. You should
always save your target configuration files to this location.
If the saved output is to be used as a configuration file, the filename should end with the cfg suffix
for easy identification. This suffix is not required, but can help locate target configuration files.
Example: myconfig.cfg
In the following example, a target configuration file is saved to the default user directory:
RP/0/RP0/CPU0:router# configure
RP/0/RP0/CPU0:router(config)# show configure | file disk0:myconfig.cfg
RP/0/RP0/CPU0:router(config)# abort
RP/0/RP0/CPU0:router#
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-146 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
router static
address-family ipv4 unicast
0.0.0.0/0 10.21.0.1
0.0.0.0/0 pos0/1/0/1 10.21.0.1
!
!
interface pos0/1/0/1
ipv4 address 10.21.54.31 255.255.0.0
!
Note For more information, see the Using Wildcards to Identify Interfaces in show Commands section on
page 6-155.
interface POS0/1/0/0
ipv4 address 10.2.3.4 255.255.255.0
pos
crc 32
!
shutdown
keepalive disable
!
interface POS0/1/0/1
ipv4 address 10.2.3.5 255.255.255.0
pos
crc 32
!
shutdown
keepalive disable
!
interface POS0/1/0/2
ipv4 address 10.2.3.6 255.255.255.0
pos
crc 32
!
shutdown
keepalive disable
!
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-147
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
interface POS0/1/0/3
ipv4 address 10.2.3.7 255.255.255.0
pos
crc 32
!
shutdown
keepalive disable
!
--More--
Command Description
show command | begin regular-expression Begins unfiltered output of the show command with the first line that
contains the regular expression.
show command | exclude regular-expression Displays output lines that do not contain the regular expression.
show command | include regular-expression Displays output lines that contain the regular expression.
show command | file device0:path/file Saves output of the show command to the specified file on the specified
device.
show command | utility name Displays a set of UNIX utilities:
cutCuts characters or lines from the output displayed from standard
input or a file.
egrepSearches a file using full regular expressions.
fgrepSearches a file for a fixed character string.
headCopies bytes or lines at the beginning of the output displayed
from standard input or a file.
lessDisplays the output of a file in a page-by-page manner.
sortSorts, merges, or sequence-checks the output displayed from
standard input or a file.
tailCopies the end portion of the output displayed from standard
input or a file.
uniqDisplays or removes repeated lines in a file.
wcCount words, lines, or bytes in a file.
xargsInvokes a program from one or more argument lists.
In the following example, the show interface command includes only lines in which the expression
protocol appears:
RP/0/RP0/CPU0:router# show interface | include protocol
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-148 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
Note Filtering is available for submodes, complete commands, and anywhere that <cr> appears in the ?
output.
Building configuration...
line console
exec-timeout 120 120
!
logging trap
--More--
/ip
filtering...
ip route 0.0.0.0 255.255.0.0 pos0/2/0/0
interface pos0/2/0/0
ip address 172.19.73.215 255.255.0.0
end
Tip On most systems, Ctrl-Z can be entered at any time to interrupt the output and return to EXEC mode.
For more information, see Appendix A, Understanding Regular Expressions, Special Characters, and
Patterns.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-149
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
Multipipe Support
The multipipe feature supports the multiple pipes on the CLI. With this feature, the output can be
processed by an enhanced utility set. Using various combination of utilities, it is possible to gather, filter,
and format the output of any show command. An arbitrary limit of eight pipes is supported on CLI with
this limit superseded by the limit of characters that can be typed on the single line (1024) if the individual
commands specified with pipes are long enough.
In addition, if you want to give pipe character (|) as a pattern, you must give it in double quotes. For
example:
RP/0/RP1/CPU0:single8-hfr# show running-config|include bgp|ospf|file disk0:/usr/a.log
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-150 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
show
show configuration merge
show configuration running sanitized desanitize rpl
show configuration running sanitized
show configuration running
show configuration
show configuration failed noerrors
show configuration failed
show configuration failed load
show running-config
show running-config sanitized desanitize rpl
show running-config sanitized
show running-config submode
show parser dump
show history detail
show history
pwd
exit
In the preceding example the install command is an admin mode command that you can run from SDR
by prefixing admin keyword.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-151
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
Note The location keyword must be available only for the disk or any media storage available on RP. Network
files do not require this keyword.
interface POS0/2/0/0
shutdown
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-152 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
!
interface POS0/2/0/1
shutdown
!
interface GigabitEthernet0/3/0/0
shutdown
!
interface GigabitEthernet0/3/0/1
shutdown
!
interface POS0/4/0/0
shutdown
!
interface POS0/4/0/1
shutdown
Note The configuration display interface slot-order command is supported only in the SDR configuration
mode.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-153
Chapter 6 CLI Tips, Techniques, and Shortcuts
Displaying System Information with show Commands
Notice that the POS interfaces have no configurations but they are still shown in the output of the
command.
This option is not applicable to other variants of show configuration commands like the following:
show configuration
show configuration commit changes
show configuration rollback changes
show configuration failed
show configuration persistent
After this command has been configured, the output of the show command forcefully displays the subnet
mask in a prefix length format. Also, you can disable the command by using the no form of the
command.
RP/0/RP0/CPU0:router# no ipv4 netmask-format bit-count
RP/0/RP0/CPU0:router#
Note This ipv4 netmask-format hit-count command is supported only in the SDR configuration mode.
The following example shows the output of a show running-config command after the ipv4
netmask-format bit-count command has been configured:
RP/0/RP0/CPU0:router# show running-config interface mgmtEth 0/RP0/CPU0/0
Mon May 31 23:48:17.453 DST
interface MgmtEth0/RP0/CPU0/0
description Connected to Lab LAN
ipv4 address 172.29.52.70 255.255.255.0
!
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-154 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Wildcards, Templates, and Aliases
Note The wildcard (*) must be the last character in the interface name.
Example
The following example shows how the configuration for all POS interfaces in rack 0, slot 1 is displayed.
RP/0/RP1/CPU0:router:router# show running-config interface pos0/1/*
interface POS0/1/0/0
ipv4 address 10.2.3.4 255.255.255.0
pos
crc 32
!
keepalive disable
interface POS0/1/0/1
ipv4 address 10.2.3.5 255.255.255.0
pos
crc 32
!
keepalive disable
interface POS0/1/0/2
ipv4 address 10.2.3.6 255.255.255.0
pos
crc 32
!
keepalive disable
interface POS0/1/0/3
ipv4 address 10.2.3.7 255.255.255.0
pos
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-155
Chapter 6 CLI Tips, Techniques, and Shortcuts
Wildcards, Templates, and Aliases
crc 32
!
keepalive disable
--More--
The following example shows how the state of all POS interfaces is displayed:
RP/0/RP1/CPU0:router# show interfaces pos* brief
SUMMARY STEPS
1. configure
2. template template-name [($parameter $parameter...)] [config-commands]
3. Enter the template commands.
4. end-template
5. commit
6. show running-config template template-name
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-156 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Wildcards, Templates, and Aliases
DETAILED STEPS
Example:
Router# configure
Step 2 template template-name [($parameter Enters template configuration mode and creates a template.
$parameter...)] [config-commands]
template-nameUnique name for the template to be
applied to the running configuration.
Example:
RP/0/RP0/CPU0:router(config)# template tmplt_1
(Optional) parameterActual values of the variables
specified in the template definition. Up to five
parameters can be specified within parentheses. Each
parameter must begin with the $ character. Templates
can be created with or without parameters.
(Optional) config-commandsGlobal configuration
commands to be added to the template definition. Any
name in a command (such as the server name, group
name, and so on) can be parameterized. This means that
those parameters can be used in the template commands
(starting with $) and replaced with real arguments when
applied.
To remove the template, use the no form of this
command.
Step 3 Enter the template commands. Defines the template commands.
Example:
RP/0/RP0/CPU0:router(config-TPL)# hostname test
Step 4 end-template Ends the template definition session and exits template
configuration mode.
Example: When you end the template session, you are returned to
RP/0/RP0/CPU0:router(config-TPL)# end-template global configuration mode.
Step 5 commit Applies the target configuration commands to the running
configuration.
Example:
RP/0/RP0/CPU0:router(config-TPL)# commit
Step 6 show running-config template template-name Displays the details of the template.
Example:
RP/0/RP0/CPU0:router# show running-config
template tmplt_1
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-157
Chapter 6 CLI Tips, Techniques, and Shortcuts
Wildcards, Templates, and Aliases
Examples
The following example shows how a simple template is defined. The template contents are then
displayed with the show running-config template template-name command:
RP/0/RP0/CPU0:router# configure
RP/0/RP0/CPU0:router(config)# template jbtest
RP/0/RP0/CPU0:router(config-TPL)# hostname test
RP/0/RP0/CPU0:router(config-TPL)# end-template
RP/0/RP0/CPU0:router(config)# commit
RP/0/RP0/CPU0:router(config)# show running-config template jbtest
template jbtest
hostname test
end-template
In the next example, a template is defined, and the template requires a parameter. The template contents
are then displayed with the show running-config template template-name command:
RP/0/RP0/CPU0:router# configure
RP/0/RP0/CPU0:router(config)# template test2 (hostname)
RP/0/RP0/CPU0:router(config-TPL)# hostname $hostname
RP/0/RP0/CPU0:router(config-TPL)# end-template
RP/0/RP0/CPU0:router(config)# commit
RP/0/RP0/CPU0:router(config)# show running-config template test2
Examples
In the following example, a simple template is defined. The template contents are then displayed with
the show running-config template template-name command:
RP/0/RP0/CPU0:router# configure
RP/0/RP0/CPU0:router(config)# apply-template jbtest
RP/0/RP0/CPU0:router(config)# show configuration
Building configuration...
hostname test
end
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-158 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Wildcards, Templates, and Aliases
In the next example, a template with one parameter is applied and the show configuration command
displays the result:
RP/0/RP0/CPU0:router# configure
RP/0/RP0/CPU0:router(config)# apply-template test2 (router)
RP/0/RP0/CPU0:router(config)# show configuration
Building configuration...
hostname router
end
Aliases
With the Cisco IOS XR software, you can define command-line aliases for any physical or logical entity
in a router. After you define the alias, it is used in the CLI to reference the real entity.
To create a command alias, enter the alias command in global configuration or administration
configuration mode:
alias alias-name [(parameter1 parameter2...)] command-syntax [$parameter1] [command-syntax]
[$parameter2]
Table 6-5 defines the alias command syntax.
Multiple commands can be supported under a single command alias, and multiple variables can be
supported for each command. If multiple commands are specified under a single alias, each command is
executed in the order in which it is listed in the alias command.
In the following example, an alias named my-cookie is created for the Management Ethernet interface,
and then the new alias is specified to enter interface configuration mode:
RP/0/RP0/CPU0:router(config)# alias my-cookie mgmtEth 0/0/CPU0/0
RP/0/RP0/CPU0:router(config)# interface my-cookie
RP/0/RP0/CPU0:router(config)# interface mgmtEth 0/0/CPU0/0
RP/0/RP0/CPU0:router(config-if)#
After you enter a command with an alias, the router displays the command you entered with the alias
value so that you can verify that alias value.
To delete a specific alias, enter the no form of the alias command with the alias name.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-159
Chapter 6 CLI Tips, Techniques, and Shortcuts
Command History
Command History
The Cisco IOS XR software lets you display a history of the most recently entered and deleted
commands. You can also redisplay the command line while a console message is being shown. The
following sections describe the command history functionality:
Displaying Previously Entered Commands, page 6-160
Recalling Previously Entered Commands, page 6-160
Recalling Deleted Entries, page 6-161
Redisplaying the Command Line, page 6-161
Displaying Persistent CLI History, page 6-161
Note To roll back to a previously committed configuration, see Managing Configuration History and
Rollback.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-160 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Command History
Table 6-6 lists the commands or key strokes to use to recall commands from the history buffer.
Note The Esc, y key sequence does not function unless the Ctrl-Y key combination is pressed first. If the
Esc, y is pressed more than ten times, the history cycles back to the most recent entry in the buffer.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-161
Chapter 6 CLI Tips, Techniques, and Shortcuts
Key Combinations
To display the history of commands from each session along with user name, enter the show cli history
detail location command at the EXEC mode as follows:
The detail option displays the commands from each session along with user name and vty id so that
commands issued from a session can be related with the session history displayed in the brief option.
Note The default size is 500 for the brief option of the command. The default size is 1000 for the detail option
of the command.
Key Combinations
The following sections provide information on key combinations:
Key Combinations to Move the Cursor, page 6-162
Keystrokes to Control Capitalization, page 6-163
Keystrokes to Delete CLI Entries, page 6-164
Transposing Mistyped Characters, page 6-164
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-162 OL-24754-01
Chapter 6 CLI Tips, Techniques, and Shortcuts
Key Combinations
Note Cisco IOS XR commands are generally case insensitive and typically all in lowercase.
Keystrokes Purpose
Esc, c Makes the letter at the cursor uppercase.
Esc, l Changes the word at the cursor to lowercase.
Esc, u Makes letters from the cursor to the end of the word uppercase.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
OL-24754-01 6-163
Chapter 6 CLI Tips, Techniques, and Shortcuts
Key Combinations
Keystrokes Deletes
Delete or Backspace Character to the left of the cursor.
Ctrl-D Character at the cursor.
Ctrl-K All characters from the cursor to the end of the command line.
Ctrl-U or Ctrl-X All characters from the cursor to the beginning of the command line.
Ctrl-W Word to the left of the cursor.
Esc, d From the cursor to the end of the word.
Cisco IOS XR Getting Started Guide for the Cisco CRS-1 Router
6-164 OL-24754-01