本文描述Cisco IOS Shell (IOS.sh) CLI模块。
Cisco建议您有Cisco IOS版本15.1(4)M、15.1(2)S及以后版本知识。必须配置和启用思科IOS.sh为了使用思科IOS.sh功能和功能在您的路由器。
本文档中的信息基于下列硬件和软件版本:
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您使用的是真实网络,请确保您已经了解所有命令的潜在影响。
思科IOS.sh是在Cisco IOS CLI允许您使用shell script程序的模块。此模块帮助自动化定期操作并且简化设备管理。它可以与其他管理工具一道使用例如Cisco IOS被嵌入的活动管理器(EEM)。
为了启用在设备的Shell CLI,请输入:
Switch#terminal shell
为了禁用Shell CLI,请输入:
Switch#terminal no shell
此功能支持PATH变量,包含目录列表shell能搜索功能/applet。并且, Shell CLI支持这些功能:
Switch#show version | grep 15.1
Cisco IOS Software, s2t54 Software (s2t54-ADVENTERPRISEK9-M),
Version 15.1(1)SY, RELEASE SOFTWARE (fc2)
Switch#show version | grep 15 > bootdisk:version.txt
Switch#dir bootdisk:
Directory of bootdisk:/
14 -rw- 280 Nov 15 2012 23:25:32 +00:00 version.txt
1024557056 bytes total (577273856 bytes free)
Switch#cat bootdisk:version.txt
Cisco IOS Software, s2t54 Software (s2t54-ADVENTERPRISEK9-M),
Version 15.1(1)SY, RELEASE SOFTWARE (fc2)
思科IOS.sh包含帮助创建申请和过滤器对用户功能的几内置的applet :
[[ evaluate a logical test expression
cat output data from a pipe or file to the terminal
cut edit piped output
echo echo arguments to the terminal
false return false in while or if expressions, and set the result
fetch return values from the configuration database
grep search for regular expressions in piped output or files
head print the first lines in the input
interface print interfaces that match the argument
let evaluate a numeric expression, and set the result
man print information for built-ins
more page piped output to the terminal
nl number the lines in the input
null ignore the input
printf output formatted data to the terminal
read read input into variables
set_oper set operational values
sleep pause execution of the terminal
sort sort the input
tail print the tail of the input
true return true in while or if expressions, and set the result
uname print system information
wc count lines, words, and characters
这是的命令,如果….然后….其他操作员。
Switch#x=5
Switch#if [[ $x != 5 ]];
then.else.fi>then
then.else.fi>echo false;
then.else.fi>else
else..fi>echo true;
else..fi>fi;
true
Switch#
这些比较操作符用于为了与整数值一起使用:
操作员 | 说明 |
- eq | Arg1-eq Arg2。真,如果Arg1与Arg2是相等的 |
- ne | Arg1-ne Arg2。真,如果Arg1与Arg2不是相等的 |
- Lt | Arg1-lt Arg2。真,如果Arg1比Arg2是较少 |
- gt | Arg1-gt Arg2。真,如果Arg1比Arg2极大 |
- ge | Arg1-ge Arg2。真,如果Arg1是greate比或等于对Arg2 |
- le | Arg1-le Arg2。真,如果Arg1是小于或等于Arg2 |
这些情况是可用为了与文件一起使用:
操作员 | 说明 |
- a或- e | 真,如果文件存在 |
- d | 真,如果文件存在和它是目录 |
- f | 真,如果文件存在并且是一个正常文件 |
- r | 真,如果文件存在并且是可读的 |
- s | 真,如果文件存在并且有极大大小比零 |
- w | 真,如果文件存在并且是可执行的 |
- nt | 如果file1比file2,新请测试。在文件的修改日期使用此比较 |
- ot | 如果file1比file2,旧请测试 |
为了使用在比较操作符内的几个条件,您能使用这些逻辑运算符:
&& Logical AND
|| Logical OR
环路是相同的正如在Linux shell。两个操作员是可用的。
这是的命令操作员的:
Switch#for x in 11
do..done>do
do..done>ping 192.0.2.$x
do..done>done
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.0.2.10,timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Switch#
这是一会儿操作员的命令:
Switch#for i in 1 2 3
do..done>do
do..done>while [ $i -lt 3 ]
do..done>do
do..done>echo $i
do..done>done
do..done>i=i+1
do..done>done
Switch#
串比较,如果….然后….其他操作员可以与这些修改一起使用:
操作员 | 说明 |
== | 字符串1 == string2,真,如果字符串是相等的。 |
! = | String1! = string2,真,如果字符串不是相等的 |
< | String1 < string2,真,如果string1比string2词典地是较少 |
> | String1 > string2,真,如果string1比string2词典地极大 |
Switch#function add_desc() {
{..} >show running-config interface Gi$1
{..} >configuration terminal
{..} >interface Gi$1
{..} >description $2
{..} >end
{..} >show running-config interface Gi$1
{..} >}
Switch#add_desc 5/1 SHELL_TEST
Building configuration...
Current configuration : 74 bytes
!
interface GigabitEthernet5/1
ip address 192.0.2.10 255.255.255.0
end
Enter configuration commands, one per line. End with CNTL/Z.
Building configuration...
Current configuration : 98 bytes
!
interface GigabitEthernet5/1
description SHELL_TEST
ip address 192.0.2.10 255.255.255.0
end
Switch#
使用本部分可确认配置能否正常运行。
输入show terminal命令为了显示当前终端的配置:
Switch#show terminal
Line 2, Location: "", Type: "XTERM-COLOR"
Length: 44 lines, Width: 155 columns
Baud rate (TX/RX) is 9600/9600
Status: PSI Enabled, Ready, Active, No Exit Banner, Ctrl-c Enabled
........
Preferred transport is lat.
Shell: enabled
Shell trace: off
输入显示shell功能命令为了显示所有功能可用在模块,包括用户定义的功能:
Switch#show shell functions
#User defined functions:
Function namespace: DEFAULT
function add_desc()
{
show running-config interface Gi$1
configure terminal
interface Gi$1
description $2
end
show running-config interface Gi$1
}
目前没有针对此配置的故障排除信息。