Klish用户手册(老板,sonic框架版本)

在UNIX系统上实现类似CISCO CLI的模块化框架。可以使用XML文件定义任意的命令菜单和操作。这个软件处理用户交互,并分支适当的系统命令来执行任何操作。

Features 特性

原子操作

[script 可以是可中断的或不可中断的(原子的),它通常与 locking_mechanism 锁机制一起使用。

为了使动作原子化,脚本必须是不可中断的。在执行ACTION脚本时,可以阻塞以下信号:

  • SIGINT 
  • SIGQUIT 
  • SIGHUP 

因此用户不能使用Ctrl^C来终止当前进程。信号阻塞现在是默认的行为。信号阻塞由sigprocmask()函数实现。被阻塞的掩码将被所有执行的进程继承。

为了使动作可中断,COMMAND标签必须包含interrupt="true"字段。例如,'ping'命令可以被中断。

<COMMAND name="ping"   
	help="Send messages to network hosts"
	interrupt="true">  
	...   …
</COMMAND>  

守护进程执行

注意当ACTION是非可中断的时,脚本中的守护进程执行不够安全,因为许多服务(守护进程)使用SIGHUP(或其他信号)来完成其工作。例如,SIGHUP是经常重读配置文件的信号。但是当ACTION是非可中断的时,服务将从脚本继承信号掩码,因此一些信号将被掩码,服务将永远不会得到这些信号。启动服务的正确方法是使用特殊的工具sigexec。这个工具将揭示所有信号,然后执行命令行中指定的命令:

# sigexec /etc/init.d/vsftpd start# sigexec /etc/init.d/vsftpd 启动

每次启动服务时使用 [sigexec] 实用程序,服务环境会更适合。

内置函数。

原始的clish包含一组内置函数,不需要在ACTION标签中使用脚本。

<COMMAND name="logout" 
    help="Logout of the current CLI session">
    <ACTION builtin="clish_close"/>
</COMMAND> 

额外的Klish特定的内置函数是可用的。

clish_nested_up

Klish支持嵌套视图。当用户在视图的层次结构中移动得更深时(“深度”在增加),引擎会在“嵌套”堆栈中创建条目来保存之前的视图及其状态。clish_nested_up函数执行“弹出”堆栈操作,以便恢复之前的[及其状态。如果当前深度为0,那么clish_nested_up函数将是内置函数clish_close的模拟,并将关闭当前Klish会话。

clish_nop

它什么也不做。它对注释之类的命令很有用。CISCO使用“!”作为注释。如果命令没有ACTION标签,那么这个命令是未完成的,所以“Enter”键不能按下。使用clish_nop对空命令。不要使用 <ACTION></ACTION> ,因为它更慢。

类似于Cisco的配置支持

在某些情况下,如果没有配置命令的存储,CLI是相当无用的。新的XML标签[被实现来支持Klish和一些外部(或内部)机制之间的交互,以存储一些命令序列,例如CISCO-like配置。在每个成功执行的命令上,Klish可以执行特殊的回调函数,以获取当前的命令信息,并可以与外部工具通信以存储命令,或内部机制可以用于配置存储。

存储配置的默认工具是konfd守护进程,可以通过套接字接口访问。

标签用于使Klish存储当前命令或执行其他操作(删除旧的条目,将条目转储到文件)在配置上。

命令别名 

命令可以有别名,结果的别名除了命令名、帮助文本和内部变量  ${__cmd}  的值以外,都等于原始命令。

为了找出用户输入的是什么名字(原始的或别名),可以分析 ${__cmd} 内部变量。 ${__orig_cmd} 变量包含原始命令的名称(别名的目标)。有关内部变量的详细信息,请参阅内部变量页面。 ${__cmd} 可以在[和[tag]的conditional_param 'test'字段中分析。

COMMAND标签的'ref'字段用于创建命令的别名,下面的例子为view1中的原始命令"show running-config"创建了别名(名为"info"):

<COMMAND name="info" ref="show running-config@view1" help="Alias for the show running-config command"/>

下面的例子创建了别名(命名为“conf”)从当前视图(“conf”和“info”命令的视图):

<COMMAND name="conf" ref="info" help="Alias for the info command"/>

条件参数 

参数可以根据条件动态启用或禁用,条件语法与标准的/bin/test 工具相同,因此参数可见性可以依赖于之前的参数值。

标签有可选的'test'字段. 'test'字段包含要计算的表达式. 如果表达式计算为false,则PARAM不会出现在CLI shell中,并且${ param_name}变量将为空. 如果PARAM被禁用,则可以认为它作为参数不存在. 内部变量和前面的参数值可以在表达式中使用. 下面的语法用于构造表达式(来自OpenBSD手册页):

 -n string 
         如果字符串长度不为零,则返回true。
 -z string 
         如果字符串的长度为零,则为真。
 s1 = s2 
         如果字符串s1和s2是相同的,则返回true。
 s1 != s2 
         如果字符串s1和s2不相同,则返回true。
 s1 < s2 
         如果字符串s1在字符串s2之前,则返回True。(ASCLL)
 s1 > s2 
         如果字符串s1在字符串s2之后,则返回True。
     
 s1      如果s1不是空字符串,则返回true。
 n1 -eq n2   
         如果整数n1和n2在代数上相等,则为真。
 n1 -ne n2 
         如果整数n1和n2在代数上不相等,则为true。
 n1 -gt n2  
         如果整数n1在代数上大于整数n2. 
 n1 -ge n2  
         如果整数n1在代数上大于或等于n2.
 n1 -lt n2 
         如果整数n1在代数上小于整数n2,则返回true。
 n1 -le n2 
         如果整数n1在代数上小于或等于整数n2。
 The -a这些基本类型可以与以下操作符组合使用。
 操作符的优先级高于 -o 操作符。
 ! expression 
         如果表达式为假,则为真。
 expression1 -a expression2
         如果 expression1 和 expression2 都为真,则返回 True。
 expression1 -o expression2
         如果 expression1 或 expression2 中的一个为真,则返回 True。
 ( expression )  
         如果表达式为真,则为真。

这个例子演示了参数“size”,如果“proto”是“ip”或“ipv6”,则将启用它,如果proto是“arp”,则将禁用它。

<COMMAND name="ping" 
	help="Send messages to network hosts">
	<PARAM name="proto"   
		help="Protocol to use for the ping"
		optional="true"   
		mode="switch"   
		ptype="SUBCOMMAND">
		<PARAM name="ip"  
			help="Send ICMP IPv4 messages to network hosts (default)
			mode="subcommand"   
			ptype="SUBCOMMAND"/>  
		<PARAM name="ipv6"  
			help="Send ICMP IPv6 messages to network hosts"机"
			mode="subcommand"  
			ptype="SUBCOMMAND"/>   
		<PARAM name="arp"  
			help="Send ARP requests to a neighbour host"
			mode="subcommand"   
			ptype="SUBCOMMAND"/>  

	</PARAM>  

	...   …

	<PARAM name="size"  
		test='"${proto}"!="arp"'   
		help="Packet size"   
		optional="true"   
		mode="subcommand"   
		ptype="SUBCOMMAND">   

		<PARAM name="psize"   
			help="Number of data bytes to send
			ptype="UINT"/>   

	</PARAM>  

	...   …

</COMMAND>   

可编程的hotkeys

键组合(热键)可以被编程来执行指定的动作。使用[HOTKEY]标签来定义热键和它的动作。所有的[VIEW](包括全局隐式视图)可以包含[HOTKEY]标签来定义这个[VIEW]的热键。如果当前的[VIEW]是一个嵌套的,那么Klish引擎将首先在当前的[VIEW]中搜索热键定义,然后在上面的[VIEW]中搜索,以此类推。所以你可以在全局[VIEW]中定义[HOTKEY],所有其他的[VIEW]将共享这个定义。

See the example: 请看示例:

<HOTKEY key="^Z" cmd="exit"/>

<VIEW name="enable_view" ...>
	...   …
	<HOTKEY key="^@" cmd="show"/>
	...   …
</VIEW>  

<VIEW name="configure-view" ...>
	...   …
	<HOTKEY key="^@" cmd="do show"/>
	...   …
</VIEW>   

Ctrl^Z  用于退出。它是在全局 [VIEW] 中定义的,并且将在所有 [VIEW] 中起作用(在这种情况下,它不会在嵌套的 [VIEW] 中重新定义)。第二个热键是 " Ctrl^@ "。 Ctrl^@ " 和 " Ctrl^spacebar " 组合给出了这个关键代码。这个热键将在 "enable-view" 及其所有子视图中执行 "show" 命令,但在 "configure-view" [VIEW] 及其所有子视图中执行 "do show" 命令。

自动内部变量

Klish引擎生成的自动变量可以像来自[PARAM]或[VAR]标签的变量一样使用。要指定这些变量,请使用${  <name> } 语法。这些变量将在执行[ACTION]脚本或使用某些标签的动态字段和允许使用变量之前展开。例如,[CONFIG]的“pattern”属性。

${__cmd}

${__cmd}  包含当前命令的名称。

${__orig_cmd}

如果当前命令是别名,则  ${__orig_cmd}  包含原始命令的名称。如果当前命令不是别名,则  ${__orig_cmd}  等于  ${__cmd} 。

${__full_cmd}

${__full_cmd}  是输入的命令名,当命令使用简单时, ${__full_cmd}  将等于  ${__cmd}  变量,但当命令是从另一个 [VIEW] 中使用带有指定的 “prefix” 属性的 [NAMESPACE] 标签导入时, ${__full_cmd}  将包含命令的完整名称 " <prefix>   <command> "。

例如,在“enable-view”[VIEW]中定义了“show”命令。当前的[VIEW]是“configure-view”。使用带有属性 prefix="do" 的[NAMESPACE]标签将“enable-view”[VIEW]导入到“configure-view”。如果用户在命令行中输入“do show”,则 ${__cmd} ="show",但 ${__full_cmd} ="do show"。

${__params}

${__params}  包含所有输入的命令参数,它等于用户输入的没有命令名的行,如果其中一个参数包含空格,那么该参数将在  ${__params}  行中引用。

${__line}

等于 " ${__cmd}   ${__params} "。

${__full_line}

${__full_line}  等于 " ${__full_cmd}   ${__params} "。

${__prefix}

I如果当前命令是使用带有指定前缀的 [NAMESPACE] 标签从另一个 [VIEW] 导入的,那么  ${__prefix}  将包含实际输入的前缀(前缀定义可以是一个 regexp)。

${__prefix<num>}

如果当前命令在嵌套导入的情况下有多个前缀,那么  ${__prefix<num>}  将包含实际输入的编号为  <num>  的前缀,而  ${__prefix0}  则等于  ${__prefix} 。

${__cur_depth}

${__cur_depth}  包含了当前嵌套视图的深度。注意,它不是当前命令本机 [VIEW] 的深度,而是当前活动 [VIEW] 的深度。当使用 [NAMESPACE] 标签从另一个 [VIEW] 导入命令时,这些值是不相等的。

${__cur_pwd}

${__cur_pwd}  包含了当前 [VIEW] 的“路径”。视图可以嵌套,而将视图切换到当前 [VIEW] 的命令就是当前的“路径”。这些命令被引号括起来,并用空格分隔。通常在与 [konfd] 守护进程通信时使用“路径”。它允许在运行配置中查找当前命令的位置和深度。

${__interactive}

${__interactive}  可以用来判断 clish 会话是交互式的( ${__interactive}  等于 "1")还是非交互式的( ${__interactive}  等于 "0"). 默认情况下, 会话是交互式的. 但是, clish 工具可以使用 "--background" 选项来使会话非交互式的.

${__width}

当前终端宽度(列)。

${__height}

当前终端高度(行)。

${__watchdog_timeout}

当前看门狗超时。当看门狗不活动时,值为“0”。

自动变量使用示例

这个例子展示了在 CONFIG 的模式字段中使用自动内部变量  ${__line} 。

<COMMAND name="interface ethernet"
	help="Ethernet IEEE 802.3"
	view="configure-if-view" 
	viewid="iface=eth${iface_num}">
	<PARAM name="iface_num"   
		help="Ethernet interface number"
		ptype="IFACE_NUM"/>  
	<CONFIG priority="0x2001" pattern="^${__line}$"/>
</COMMAND> 

锁定机制 

锁定机制允许同时执行多个clish utility(或基于libclish库的其他程序)实例,而不会产生冲突。它通常与原子操作一起使用。

在命令执行之前,Klish引擎会尝试获取锁。锁的实现是一个fcntl文件锁调用,在“/tmp/clish.lock”文件上。如果进程不能获取锁,它会重复尝试获取锁,在多次尝试之间使用短的sleep()。失败意味着有人早先获取了锁。如果进程获取了锁,它会执行命令的ACTION,然后解锁文件。

有些命令不需要锁定机制。例如“ping”。这是一个独立的命令。几个“ping”可以同时执行。但是那些可以改变用户配置或一些系统设置的命令需要锁定机制。因此,锁定机制可以根据每个命令启用/禁用。[COMMAND]标签具有“锁定”属性,可以是“true”或“false”。它是“true”的默认值。但是如果它是“false”,Klish引擎将不会尝试在执行该命令之前获取锁。

无锁的“ping”命令示例:

<COMMAND name="ping"   
	help="Send messages to network hosts"
	lock="false"> 
	...   …
</COMMAND> 

.有时需要禁用整个clish会话的锁定机制。如果clish工具从命令的[ACTION]中的另一个clish实例中使用,它很有用。该命令已经获得了锁,所以嵌套的clish无法获得锁。嵌套的clish可以使用“-l”(或“--lockless”)选项来禁用锁定机制。

嵌套执行 clish 的示例:

<COMMAND name="nested"  
	help="This command use nested clish utility">
	<ACTION>   
		echo "ping www.google.com" | clish --locklessping www.google.com 
	</ACTION>   
</COMMAND> 

嵌套参数和参数分支 

参数可以嵌套,即[可以包含另一个子-PARAMs。

如果父参数没有被设置,因为它是optional_arguments optional,或者引擎选择了另一种执行方式,那么分支的子参数将不会被考虑,相应的变量将被取消设置。 在分析子参数后,引擎将继续正常的流程,并将分析父参数之后的下一个参数(其中包含子参数)。

命名空间或逻辑嵌套视图 

标签[NAMESPACE]允许使用“ref”属性将命令集从指定的视图导入到另一个视图中。 因此这些命令可以在目标视图中使用。它允许创建逻辑嵌套的视图。层次结构中的进一步视图可以使用之前视图的命令。行为类似于CISCO模式(可以从“config-if”模式使用“configure”模式命令)。参见NAMESPACE标签描述。

逻辑嵌套视图

下面的代码演示了命令集导入的使用。假设当前视图是“view2”。命令“com1”将是可用的,尽管它属于“view1”。此外,在导入时,将启用来自“view1”的命令的帮助和完成。

<VIEW name="view1" prompt="(view1)# ">
	<COMMAND name="com1" help="Command 1">
		<ACTION>echo "com1"</ACTION>
	</COMMAND>  
</VIEW>  
<VIEW name="view2" prompt="(view2)# ">
	<NAMESPACE ref="view1"  
		help="true"  
		completion="true"/> 
	<COMMAND name="com2" help="Command 2">
		<ACTION>echo "com2"</ACTION>
	</COMMAND>   
	<COMMAND name="exit" help="Exit">
		<ACTION builtin="clish_close"/>
	</COMMAND>  
</VIEW>  

带前缀的命名空间

下面的代码和前面的例子做同样的事情,但是来自“view1”的命令可以使用前缀“do”。注意“view2”中名为“do”的新命令。这个命令对于Klish解析任何带有这个前缀的命令是必要的。

	<VIEW name="view1" prompt="(view1)# ">
	<COMMAND name="com1" help="Command 1">
		<ACTION>echo "com1"</ACTION>
	</COMMAND> 
</VIEW>  
<VIEW name="view2" prompt="(view2)# ">
	<NAMESPACE ref="view1" 
		prefix="do"  
		help="true"  
		completion="true"/>  
	<COMMAND name="do" help="Import prefix"/>

	<COMMAND name="com2" help="Command 2">
		<ACTION>echo "com2"</ACTION>
	</COMMAND> 
	<COMMAND name="exit" help="Exit">
		<ACTION builtin="clish_close"/>
	</COMMAND>
</VIEW>  

恢复命令上下文

当嵌套视图的层次结构被建立时,较低的视图通常继承来自更高视图的命令。对于类似于CISCO的配置模式来说,这是真的。请参阅源代码树中的Klish XML示例。例如,如果当前视图是“configure-if-view”(定义网络接口设置的嵌套视图),那么显然没有必要从当前视图“退出”到更高级别的视图(“configure-view”)来使用来自这个更高级别视图的命令。如果相同的命令没有在当前视图中重新定义,那么您可以直接执行这些命令。该特性用于处理普通配置文件。

默认情况下,当前视图不会被改变。这对于像“do show running-config”这样的信息命令来说是好的,因为它不会进入用户配置。但是这对于配置命令来说不是好的。这样的命令在执行时使用当前上下文(视图,深度和viewid)。因此,在执行命令之前,有必要设置命令的本地上下文。直接调用更高级别的命令等于从嵌套视图“退出”到更高级别的视图,然后执行指定的命令。为了实现这种行为,而不需要明显的“退出”,可以使用[标签的“restore”字段。

所有带有指定的'restore'字段的VIEW命令,当从另一个使用[机制的视图执行时,将恢复其上下文。详情请参阅VIEW标签的描述。如果restore="view",命令只能恢复其本机视图(将其设置为当前视图),但这通常没有用。因为这种方法不能恢复viewid,而"configure-view"可以包含相同深度的(使用来自其他VIEW的命令)。对于嵌套视图的层次结构,更有用的方法是restore="depth"。Klish引擎将找出命令的本机视图的深度。然后它将在当前的嵌套视图堆栈中搜索这个深度。当前视图将被设置为从堆栈中保存的视图,其深度等于命令的深度。此外,保存的上下文(viewid)将从堆栈中恢复。

典型的“configure-view”有restore="depth"字段:

<VIEW name="configure-view"
	prompt="${SYSTEM_NAME}(config)#"
	restore="depth"> 

	....   …

	<COMMAND name="interface"
		help="Select an interface to configure"/>

	<COMMAND name="interface ethernet"
		help="Ethernet IEEE 802.3"
		view="configure-if-view"   
		viewid="iface=eth${iface_num}">
		<PARAM name="iface_num"  
			help="Ethernet interface number"
			ptype="IFACE_NUM"/>  
		<CONFIG priority="0x2001" pattern="^${__line}$"/>
	</COMMAND>

	....   …

</VIEW> 

<VIEW name="configure-if-view"
	prompt="${SYSTEM_NAME}(config-if-${iface})# "
	depth="1">  

	...   …

	</VIEW>  

可选参数

命令参数可以是可选的。[PARAM]标签支持“可选”参数,指定参数是否是可选的。它可以是一个可选参数的序列。可选参数的顺序定义了验证值的顺序。如果值被可选参数验证,下一个可选参数将不会验证该值。每个参数只能被指定一次。参见 PARAM 标签描述。

下面的代码创建了三个可选参数和一个强制参数:

<PTYPE name="SUBCOMMAND"  
	pattern="[^\]+"  
	help="String"/>  

<COMMAND name="com2" help="Command 2">

	<PARAM name="flag"  
		help="option -c"  
		ptype="SUBCOMMAND"   
		mode="subcommand"  
		optional="true"/>  

	<PARAM name="-c"  
		help="option -c"   
		ptype="SUBCOMMAND"  
		mode="subcommand"   
		optional="true"/>   

	<PARAM name="p_int"   
		help="optional uint param"
		ptype="UINT" 
		optional="true"/> 

	<PARAM name="mandatory"   
		help="mandatory uint param"
		ptype="SUBCOMMAND"   
		mode="subcommand"/>   
	<ACTION> 
		if test "x${flag}" != "x"; then echo "flag=${flag}"; fi
		if test "x${-c}" != "x"; then echo "-c=${-c}"; fi
		if test "x${p_int}" != "x"; then echo "p_int=${p_int}"; fi
		echo "${mandatory}"  
	</ACTION>   
</COMMAND>  
如果没有输入可选参数,则对应的变量将不被设置。可选参数可以以任意顺序使用。

Ordered optional parameters有序可选参数

在前面的例子中,三个可选参数可以以任意顺序使用,例如,您可以先输入“-c”参数,然后输入“flag”参数,或者以任何其他顺序。 [标签的“order”字段将可选参数的顺序排序。

<PARAM name="flag"   <参数名称=“标志”
	help="option -c"   c选项”(help =
	ptype="SUBCOMMAND"   ptype”=“SUBCOMMAND”
	mode="subcommand"   mode=“子命令”
	optional="true"/>   可选=“true”/>

<PARAM name="-c"   < PARAM name = " c "
	help="option -c"   c选项”(help =
	ptype="SUBCOMMAND"   ptype”=“SUBCOMMAND”
	mode="subcommand"   mode=“子命令”
	optional="true"   可选=“true”
	order="true"/>   order=“true”/>

<PARAM name="p_int"   <房子里的帕拉姆=“p_int”
	help="optional uint param"可选的 uint 参数
	ptype="UINT"   ptype=“UINT”
	optional="true"/>   可选=“true”/>

注意“-c”子命令定义中的order="true”字段,如果已经输入了“-c”,那么“flag”可选参数就不能输入了,因此带有order字段的参数会切断所有之前声明的可选参数。

The clish compatibility 

clish 也支持可选参数,但有区别,“prefix” [选项定义意味着参数是可选的,前缀后面必须跟随在同一 PARAM 中指定的“ptype”参数。因此,没有前缀的参数不能是可选的。

当定义了“prefix”选项时,Klish 会模仿 clish 的行为。

  • The Klish native variant: ed6308cd3d5b352612db98dc2fbb8e37Klish 本地变体: ed6308cd3d5b352612db98dc2fbb8e37

  • The clish compatible variant: d9c67481e57f9116169fdf8af8ad18a0兼容的变体: d9c67481e57f9116169fdf8af8ad18a0

这些参数的内部表示是相同的。Klish本机变体可以显示内部表示。它使用 nested_params 嵌套参数机制。实际上,clish 变体使用内部 ptype “internal_SUBCOMMAND” 自动生成名为“-c”的可选子命令。它不能使用 “SUBCOMMAND” ptype,因为它可以是无定义的。“internal_SUBCOMMAND” ptype 具有 pattern=" [^\]+ ” 和 help="Option”。

clish 变体似乎更短,但是如果您需要多个子参数,或者如果您根本不需要任何子参数,只需要标志,那么它就不起作用。

有序序列 

.在某些情况下,需要有序的编号列表。例如,类似于CISCO的访问列表,其中条目的顺序很重要。条目可以通过行号进行寻址。

脚本语言的选择

脚本执行的脚本语言可以自定义。此外,用户可以定义整个会话的默认脚本语言。

可以为脚本执行指定http://en.wikipedia.org/wiki/Shebang_%28Unix%29 shebang,默认使用的是"/bin/sh",要自定义shebang,可以使用ACTION标签的'shebang'字段:

<COMMAND ...>   <命令…>
	...   …
	<ACTION shebang="/usr/bin/perl -w">
		print "Hello world\n";
	</ACTION>   > < /行动
</COMMAND>   > < /命令

要定义整个会话的默认 shebang,可以使用 [STARTUP] 标签的 'default_shebang' 字段:

<STARTUP default_shebang="/bin/bash" ... />默认启动目录:/bin/bash/>

子命令说明

特殊类型的[被实现。它是一个固定的单词(符号序列没有空格),可以在另一个参数中找到。子命令由其名称(或“值”字段,如果指定)标识,可以用作可选标志或用于分支。如果子命令被使用,则参数的值是其名称(如果指定,则为“值”字段)。如果参数是可选的且没有使用,则参数的值是undefined。参见PARAM标签的描述。

下面的例子展示了典型的子命令定义。

<PTYPE name="SUBCOMMAND"  
	pattern="[^\]+"   模式= " [^ \]"
	help="String"/>   help=“字符串”/>

...   …

<PARAM name="-c"  
	help="option"   
	ptype="SUBCOMMAND"  
	mode="subcommand" 
	optional="true"/>  

[标签包含“模式”选项。对于子命令,该选项必须为“子命令”。请参阅PARAM中的“模式”选项说明。“ptype”可以是任意的。引擎将使用指定的“ptype”验证[的名称。

我认为没有必要使用没有optional="true"或没有switch_subcommand分支的子命令。参见可选参数和switch子命令以获取更多信息。

子命令重复

可显示的子命令名可以通过“value”字段复制。例如,用户可以使用两个子命令“host”:

<PARAM name="host1"  
	value="host"   
	help="src host"  
	ptype="SUBCOMMAND"   
	mode="subcommand">  

	<PARAM name="ip_src"   
		help="src host ip"  
		ptype="IP_ADDR"/>  
</PARAM> 
<PARAM name="host2"   
	value="host"  
	help="dst host"   
	ptype="SUBCOMMAND">   

	<PARAM name="ip_dst"  
		help="dst host ip"  
		ptype="IP_ADDR"/>   
</PARAM>  

内部变量名将是“host1”和“host2”,但显示名称为“host”,这两个参数。“value”字段强制PARAM的模式为“subcommand”。它对其他模式没有意义。如果“value”字段没有指定,内部变量名和显示名称是相同的,并使用“name”字段。

切换子命令

T特殊类型的[被实现。switch子命令是一个容器,允许选择其子参数中的唯一一个进行进一步分析。

下面的例子显示了带有 switch 子命令的命令:

<COMMAND name="com" help="Command">

	<PARAM name="choice"   
		help="Switch subcommand"   
		ptype="STRING" 
		mode="switch">  
		<PARAM name="one"   
			help="one subcommand"
			ptype="SUBCOMMAND"  
			mode="subcommand"/>  
		<PARAM name="two"  
			help="two subcommand"  
			ptype="SUBCOMMAND"  
			mode="subcommand">  
			<PARAM name="nint"  
				help="nested int"   
				ptype="UINT"/>   
		</PARAM>  
	</PARAM>  
	<PARAM name="mandatory"  
		help="mandatory uint param"
		ptype="UINT"/>   
		<ACTION>   <行动>
			echo "Choice is ${choice}"
			echo "one is ${one}"  
			echo "two is ${two}"  
			echo "nint is ${nint}"
		</ACTION>
</COMMAND>

要定义switch子命令,必须将PARAM的选项"mode"设置为"switch"。switch子命令的"ptype"为子参数名验证定义了PTYPE。

当用户输入“com”时,他必须选择两个变量之一:“one”或“two”。因此用户选择分支进行进一步的命令行解析。名为“choice”的开关子命令将被设置为所选择的子参数的名称,以便您可以稍后分析这个值。具有所选择的子参数名称的变量将被设置为自己的名称。具有未被选择的子参数名称的变量将被取消设置。

假设我们选择了“two”子参数,这个子命令包含了一个名为“nint”的嵌套参数,下一个命令行参数将被解析为“nint”参数,然后引擎将返回到正常流程并分析“mandatory”参数,“one”变量将被取消设置,而“choice”值将为“two”,因此它实现了分支,“one”分支根本没有被使用。

The UTF-8 support UTF-8支持

Klish(clish 控制台实用工具)支持 UTF-8 和 8 位编码。

clish 工具使用区域设置信息自动检测当前编码。因此,对于 UTF-8 和传统的 8 位编码,控制台输入行为不同。

如果地区被破坏了,用户可以通过clish的实用工具命令行中的“-u”(--utf8)选项强制使用UTF-8编码。“-8”(--8bit)选项用于强制8位编码。

标签

CLISH_MODULE

.CLISH_MODULE 是最高级别的标签,它包含了所有其他的标签,通常每个 Klish 的 XML 配置文件都以 CLISH_MODULE 开始,以 CLISH_MODULE 结束。

<?xml version="1.0" encoding="UTF-8"?>"
<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
	xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
	http://clish.sourceforge.net/XMLSchema/clish.xsd">

...   …

</CLISH_MODULE>

第一行( <?xml ... )在 XML 规范中定义。使用您首选的编码。

CLISH_MODULE 可以包含以下标记:

  • [OVERVIEW] - 一次
  • [STARTUP] -一次
  • [PTYPE] -多重
  • [COMMAND] - 多
  • [VIEW]-多个
  • [NAMESPACE] - 多个
  • [VAR]  - 多个
  • [WATCHDOG] -一次
  • [HOTKEY] -多个
  • [PLUGIN] -多个
  • [HOOK] 多重
  •  [钩]-多重
  • VIEW 视图

    VIEW标签定义了一个视图,这个视图聚集了所有的命令,当Klish执行的时候,它有一个当前的视图,也就是一组当前可以访问的命令,这个视图可以通过特殊的命令来改变,然后另一个视图成为当前视图,这个视图的命令也变得可以访问了。

    VIEW标签可以包含以下标签:

  • [NAMESPACE]  - 多个
  • [COMMAND]- 多个
  • [HOTKEY] -多个

 name

  VIEW的唯一名称。VIEW可以由这个名称来引用。例如,[COMMAND]标签的“view”字段可以引用这个名称。“name”字段可以包含字母、数字、连字符、下划线。名称不能以下划线开头。

prompt

命令行提示符。当视图是活动视图时,这个字符串将是一个提示符。"prompt"字段可以包含Klish的变量,并将被展开。

[depth] 

一个嵌套视图的深度。它与[CONFIG]标签一起使用。如果命令必须写入配置,视图的深度指定了CISCO-like配置中的命令缩进。当前视图中的所有命令具有相同的深度。

The default is "0". 默认为“0”。

[restore] 

视图中包含的命令可以从嵌套视图或并行视图(参见 [NAMESPACE])中执行。一些命令需要自己的上下文才能正确执行。在命令执行时,可以恢复命令的深度(和上下文)或视图。"restore"字段的值可以是:

  • none - 不改变当前视图。
  • view  - 当前视图将被设置为命令的本机视图。
  • depth -  Klish引擎会找出命令的本地视图的深度,然后在当前的嵌套视图堆栈中搜索这个深度,当前视图将被设置为从堆栈中保存的视图,其深度等于命令的深度,另外上下文(“viewid”值)将从堆栈中恢复。
  • 默认值为“none”。请参阅嵌套视图以获取更多信息和示例。

    [access]

这个字段控制视图的访问权限。如果访问被拒绝,那么用户就不能使用这个视图中的[命令]。通常这个字段的内容是任意的。这意味着控制权限的实际函数可以通过[HOOK]标签来设置。默认情况下(内置函数),“access”字段包含要授予访问权限的UNIX组列表。这些组之间用":"符号分隔。如果访问字段没有定义,则授予访问权限。

COMMAND 命令

这个标签可以在 [VIEW] 元素的作用域内使用,也可以在全局作用域内使用。COMMAND 标签定义了命令。有关更多信息,请参阅 锁定机制。

标签可以包含以下标签:

  • [DETAIL] - 一次
  • [PARAM] -  多重
  • [CONFIG] - 一次
  • [ACTION] - -一次

 name 

help 

[ref] 

这个“ref”字段是用来创建一个命令别名。如果“ref”字段在COMMAND定义中使用,那么这个命令不是独立的,而是别名。这个“ref”包含了要创建别名的目标原始命令的名称。如果目标命令属于另一个视图而不是别名视图,那么目标命令的视图必须在目标命令名称之后指定。命令名称和视图名称之间的分隔符是“@”符号。有关详细信息和示例,请参阅命令别名页面。

[view]

[viewid] 

[access]

这个字段控制COMMAND的访问权限。如果访问被拒绝,那么用户就不能使用命令。通常这个字段的内容是任意的。这意味着控制权限的实际函数可以通过[HOOK]标签设置。默认情况下(内置函数),“access”字段包含授予访问权限的UNIX组列表。这些组由":"符号分隔。如果访问字段没有定义,则授予访问权限。

[args] {#COMMAND_args}

这个可选属性的值指定了一个变量的名称。这个变量将包含处理所有 PARAM 后剩下的所有内容。 如果这个字段存在,那么属性 args_help 也必须存在。如果这个字段不存在,则不可能输入额外的参数。

[args_help] 

附加参数的帮助字符串。

[escape_chars]

[lock] 

一个布尔标志。它可以启用(true)或禁用(false)当前命令的锁定机制。

默认值为true。

[interrupt]

指定了 [ACTION] 脚本是可中断的还是不可中断的。如果 interrupt="true" 则脚本是可中断的,否则脚本是不可中断的。对于不可中断的脚本,SIGINT 和 SIGQUIT 是临时阻塞的。

STARTUP 启动

STARTUP 标签定义了开始视图、viewid 和其他启动设置。

VIEW标签可以包含以下标签:

  • [DETAIL] - once [细节]-一次
  • [ACTION] - once [动作]-一次
  • view {#STARTUP_view}

    这个字段定义了当Klish启动时的当前[VIEW]。这个值可以通过clish命令行选项或特殊的环境变量[CLISH_VIEW]来重新定义。

    [viewid] {#STARTUP_viewid}[查看ID]{#STARTUP_viewid}

    与[COMMAND]标签中的"viewid"字段相同。该值可以通过clish命令行选项或特殊的环境变量[CLISH_VIEWID]来重新定义。

    [default_shebang] {#STARTUP_default_shebang}

    定义默认脚本执行使用的脚本语言(二进制文件)。默认是“/bin/sh”。带有“shebang”字段的[ACTION]标签可以本地重新定义其执行的shebang。

    [timeout] {#STARTUP_timeout}

    如果在指定的超时内没有任何用户活动,Klish 可以自动注销(关闭当前输入流并退出)。当管理员忘记手动关闭会话时,它可以用于自动关闭特权会话。

    [lock] {#STARTUP_lock}

    与 [COMMAND] 标签的 "lock" 字段相同。

    [interrupt] {#STARTUP_interrupt}

    与 [COMMAND] 标签的 "interrupt" 字段相同。

    [default_plugin] 

    ACTION 行动

    这个标签可以在[COMMAND]元素的范围内使用。ACTION标签定义了一个命令要执行的脚本。标签的文本内容将被展开(环境变量,Klish的[VAR],参数),并且结果文本由客户端的脚本解释器解释。此外,可选的“builtin”属性可以指定一个内部命令的名称,该命令将被调用而不是客户端的脚本处理程序。

    [builtin] {#ACTION_plugin}

    指定一个内部注册函数的名称.ACTION标签的内容被作为这个内置函数的参数.所以如果指定了"builtin"字段,那么ACTION内容将不会作为脚本执行.

    [shebang] {#ACTION_shebang}[社邦]{#ACTION_shebang}

    定义用于执行 ACTION 脚本的脚本语言(二进制文件)。

    默认是使用 [STARTUP] 标签中的 "default_shebang" 字段定义的 shebang。如果 "default_shebang" 没有定义,则使用 "/bin/sh"。

    OVERVIEW 概述

    This should provide instructions about key bindings and escape sequences which can be used in the CLI.这应该提供有关可以在 CLI 中使用的键绑定和转义序列的说明。

    DETAIL 细节

    This tag may be used within the scope of a [COMMAND] element, in which case it would typically contain detailed usage instructions including examples.这个标签可以在 [COMMAND] 元素的范围内使用,在这种情况下,它通常包含详细的使用说明,包括示例。

    This may also be used within the scope of a [STARTUP] element, in which case the text is used as the banner details which are displayed on shell startup. This is shown before any specified [ACTION] is executed.这个也可以在 [STARTUP] 元素的范围内使用,在这种情况下,文本被用作在 shell 启动时显示的 banner 细节,在执行任何指定的 [ACTION] 之前显示。

    PTYPE 定义枚举类型

    This tag may be used within the global scope. The PTYPE tag is used to define the syntax of a parameter ([PARAM]).这个标签可以在全局作用域中使用。PTYPE标签用于定义参数([PARAM])的语法。

    举例:

    <PTYPE name="MONTH_NAME"  
           method="select"   method=“选择”
           pattern="January(1) February(2) March(3) April(4) May(5) June(6) July(7) August(8) September(9) October(10) November(11) December(12)"
           help="Month of the year"/>help="月份"/>

    name {#PTYPE_name} 名字{# PTYPE_name}

    A textual name for this type. This name can be used to reference this type within a [PARAM] tag "ptype" attribute.该类型的文本名称。该名称可用于在 [PARAM] 标签的 “ptype” 属性中引用该类型。

    help {#PTYPE_help} 帮助{# PTYPE_help}

    A textual string which describes the syntax of this type.描述该类型语法的文本字符串。

    pattern {#PTYPE_pattern}

    Typically a regular expression which defines the syntax of the type. The "method" attribute can change the meaning of this field.通常是一个正则表达式,定义了类型的语法。"method"属性可以改变这个字段的含义。

    [method] {#PTYPE_method}

    The means by which the "pattern" attribute is interpreted.解释“pattern”属性的方法。

  • "regexp" [default] - A POSIX regular expression."regexp" [默认] - 一个POSIX正则表达式。
  • "integer"- A numeric definition "min..max"."integer"- 一个数值定义 "min..max"。
  • "select" - A list of possible values. The syntax of the string is of the form: "valueOne(ONE) valueTwo(TWO) valueThree(THREE)" where the text before the parenthesis defines the syntax that the user must use, and the value within the parenthesis is the result expanded as a parameter value. The parenthesis may be omitted. Then the syntax and the value are equal. 枚举类型。语法格式:"valueOne(ONE)" 文本在插入语前定义用户必须使用的格式,值在插入语括号内的可以被扩展成参数值。插入语括号可以被删除。那样语法和值就一样了。
  • [preprocess] {#PTYPE_preprocess}

    An optional directive to process the value entered before validating it. This can greatly simplify the regular expressions needed to match case insensitive values.一个可选的指令,在验证输入值之前对其进行处理。这可以极大地简化匹配不区分大小写值所需的正则表达式。

  • "none" [default] - do nothing."none"[默认] - 不做任何事情。
  • "toupper" - before validation convert to uppercase."toupper" - 在验证之前转换为大写。
  • "tolower" - before validation convert to lowercase."tolower" - 在验证之前转换为小写。
  • PARAM 停止

    This tag may be used within the scope of a [COMMAND] element. The PARAM tag defines command parameters. See the optional argumentssubcommands and switch subcommands for additional information.这个标签可以在 [COMMAND] 元素的范围内使用。PARAM 标签定义了命令参数。有关更多信息,请参阅可选参数、子命令和开关子命令。

    The VIEW tag can contain the following tags:VIEW标签可以包含以下标签:

  • [PARAM] multiple (参数)多个
  • name {#PARAM_name} 名字{# PARAM_name}

    help {#PARAM_help} 帮助{# PARAM_help}

    ptype {#PARAM_ptype}

    [mode] {#PARAM_mode}

    Define parameter behaviour. It can be:定义参数行为。它可以是:

  • common - the standard mode for ordinary parameter. Nothing special.common - 用于普通参数的标准模式。没有什么特别的。
  • subcommand - the parameter is subcommand. The subcommand is identified by its "name" (or "value" field if specified) and can be used as optional flag or for the branching. If the subcommand was used then the value of parameter is its name ("value" field if specified). The value of parameter is undefined if parameter is optional and was not used. See the subcommand and "value" field documentation for details.subcommand - 参数是子命令。子命令由其“name”(或“value”字段,如果指定)标识,可以用作可选标志或用于分支。如果使用了子命令,则参数的值是其名称(如果指定了“value”字段)。如果参数是可选的,且没有使用,则参数的值是undefined。有关详细信息,请参阅子命令和“value”字段文档。
  • switch - the parameter is switch subcommand. The switch subcommand's sub-parameters is alternative and allow branching implementation. The parameter itself get the name of choosen sub-parameter as a value. See the switch subcommand documentation for details.switch - 参数是 switch 子命令。switch 子命令的子参数是可选的,并允许分支实现。参数本身得到选择的子参数的名称作为值。详情请参阅 switch 子命令文档。
  • Default is "common". 默认值为 "common"。

    [prefix] {#PARAM_prefix}

    [optional] {#PARAM_optional}[可选] { #PARAM_optional}

    A boolean flag. Specify whether parameter is optional. The allowed values is true or false. See the Optional arguments documentation for example.一个布尔标志。指定参数是否可选。允许的值是true或false。参见Optional arguments文档中的示例。

    Default is false. 默认值为false

    [order] {#PARAM_order}

    A boolean flag. Can be used with optional (optional="true") parameters only. If current parameter is specified in command line then previously declared (in XML file) other optional parameters can't be entered later. So this option set the order of available optional parameters. See the Optional arguments documentation for example.一个布尔标志。只能与可选参数一起使用(optional="true")。如果当前参数在命令行中指定,那么之前声明的(在XML文件中)其他可选参数不能在后面输入。因此,此选项设置可用可选参数的顺序。参见Optional arguments文档中的示例。

    The allowed values is true or false. Default is false.允许的值是 true 或 false。默认值是 false。

    The feature is available since version 1.5.2.该功能从 1.5.2 版本开始可用。

    [default] {#PARAM_default}

    [value] {#PARAM_value}

    The subcommand specific option. This field is used to separate the name of internal variable and the displayable name (that user will enter). The "name" field is a name of the internal variable. The "value" is a displayable subcommand name. It allows to duplicate displayable subcommand names.子命令特定选项。这个字段用于分隔内部变量名和显示名称(用户将输入)。“name”字段是内部变量名。“value”是显示子命令名。它允许重复显示子命令名。

    The "value" field forces the mode of PARAM to "subcommand".“value”字段强制PARAM的模式为“subcommand”。

    The feature is available since klish-1.2.0.该特性从 klish-1.2.0 开始可用。

    [hidden] {#PARAM_hidden}

    The "hidden" field specify the visibility of the parameter while ${__line} and ${__params} automatic variables expanding. The expanding of variable with the PARAM name is performed by the usual way. The allowed values is "true" or "false".隐藏字段指定了参数在 ${__line} 和 ${__params} 自动变量扩展时的可见性。使用参数名进行变量扩展按通常方式执行。允许的值为“true”或“false”。

    Default is "false". 默认值为"false"

    For example this feature can be used while the ordered sequences implementation. The hidden parameter can specify the line number in ordered sequence. So it must be passed to the [konfd] daemon via "sequence" field of [CONFIG] tag but the ${__line} (that will be set to the user config) doesn't need to contain line number.例如,这个特性可以用于实现有序序列,隐藏参数可以指定有序序列中的行号,因此必须通过 [CONFIG] 标签的 "sequence" 字段传递给 [konfd] 守护进程,但是  ${__line}  (将设置为用户配置)不需要包含行号。

    [test] {#PARAM_test}

    The parameter can be dynamically enabled or disabled depending on the condition. The condition have the syntax same as standard "/bin/test" utility. So the parameter visibility can depend on the previous parameters values and internal variables. See the conditional parameters for details.参数可以根据条件动态启用或禁用。条件语法与标准的“/bin/test”工具相同。因此,参数可见性可以依赖于前面的参数值和内部变量。详情请参阅条件参数。

    By default the parameter is enabled.默认情况下,该参数是启用的。

    NAMESPACE 名称空间

    This tag may be used within the scope of a [VIEW] element. The NAMESPACE tag allows to import the command set from the specified view into another view. See the logically nested views for details on using this tag.这个标签可以在 [VIEW] 元素的范围内使用。NAMESPACE 标签允许从指定的视图导入命令集到另一个视图。有关使用这个标签的详细信息,请参阅逻辑嵌套视图。

    ref {#NAMESPACE_ref} 引用空间{ #NAMESPACE_ref}

    Reference to the [VIEW] to import commands from.引用 [VIEW] 以从中导入命令。

    [prefix] {#NAMESPACE_prefix}

    The text prefix for imported commands.导入命令的文本前缀。

    [prefix_help] {#NAMESPACE_prefix_help}

    The help string for the NAMESPACE prefix. It will be printed when user has already entered prefix but hasn't entered the command name yet.NAMESPACE前缀的帮助字符串。当用户已经输入了前缀但还没有输入命令名时,它将被打印出来。

    [help] {#NAMESPACE_help}

    A boolean flag whether to use imported commands while help (press "?" key). Can be true or false. Default is false.一个布尔标志,当帮助(按“?”键)时是否使用导入的命令。可以是true或false。默认值是false。

    [completion] {#NAMESPACE_completion}

    A boolean flag whether to use imported commands while command completion (press "Tab" key). Can be true or false. Default is true.一个布尔标志,当命令完成(按“Tab”键)时是否使用导入的命令。可以是true或false。默认值是true。

    [context_help] {#NAMESPACE_context_help}

    A boolean flag whether to use imported commands while context help. Can be true or false. Default is false.一个布尔标志,当上下文帮助时是否使用导入的命令。可以是true或false。默认值是false。

    [inherit] {#NAMESPACE_inherit}[继承] {#NAMESPACE_inherit}

    A boolean flag whether to inherit nested namespace commands recursively. Can be true or false. Default is true.一个布尔标志,表示是否递归地继承嵌套的命名空间命令。可以是true或false。默认值是true。

    CONFIG 配置

    This tag may be used within the scope of a [COMMAND] element. The CONFIG tag was implemented to support interaction between Klish engine and some external (or internal) mechanism to store a commands sequence i.e. CISCO-like configuration.这个标签可以在 [COMMAND] 元素的范围内使用。CONFIG 标签的实现是为了支持 Klish 引擎和一些外部(或内部)机制之间的交互,以存储命令序列,例如 CISCO 类的配置。

    [operation] {#CONFIG_operation}

    Defines the action on current configuration (running-config):定义当前配置的操作(running-config):

  • set - write currently entered command line to the running-config. If the command is already in the running-config it will be no changes. The "pattern" field define the uniqueness of command. If the running-config already contain entries starting with the "pattern" than these entries will be removed.set - 将当前输入的命令行写入到 running-config 中,如果该命令已经在 running-config 中,则不会发生变化。"pattern" 字段定义了命令的唯一性。如果 running-config 中已经包含了以 "pattern" 开头的条目,则这些条目将被删除。
  • unset - remove entries from the running-config due to specified "pattern".unset - 根据指定的“pattern”从运行配置中删除条目。
  • dump - write the running-config to the specified "file". If the "file" is not specified than running-config will be written directly to the communication channel (the socket in the case of [konfd] configuration backend). So the config callback function must care about data receiving. The standard callback can receive and show the data from [konfd] daemon.dump - 将运行配置写入指定的“文件”。如果没有指定“文件”,则运行配置将直接写入通信通道(在 [konfd] 配置后端的情况下是套接字)。因此,配置回调函数必须关心数据接收。标准回调函数可以从 [konfd] 守护进程接收并显示数据。
  • The default is "set". 默认值为“set”。

    [priority] {#CONFIG_priority}

    The "priority" field define the sort order within running-config. Note the order of commands is important. For example to setup routing table the interfaces must be already configured.priority 字段定义了 running-config 中的排序顺序。注意命令的顺序很重要。例如,要设置路由表,必须先配置好接口。

    The "priority" is a two-byte hex number (for example "0x2345"). The high byte defines the configuration group of command. The low byte defines the priority within the group. The configuration groups is separated from each other with "!" symbol. The commands within group can be separated or not separated with "!". The separation behaviour within group is defined by "splitter" field. For example the CISCO-like running-config will separate the definitions of interfaces with "!" but will not separate "ip route ..." and "ip default-gateway ..." commands.优先级是一个二字节的十六进制数字(例如“0x2345”)。高字节定义了命令的配置组。低字节定义了组内的优先级。配置组之间用“!” 符号分隔。组内的命令可以用“!” 分隔,也可以不分隔。组内的分隔行为由“splitter”字段定义。例如,类似于CISCO的running-config将用“!” 分隔接口的定义,但不会分隔“ip route...” 和“ip default-gateway...” 命令。

    The default is "0x7f00". It's a medium value of the high-byte.默认值为“0x7f00”,是高字节中等值。

    [pattern] {#CONFIG_pattern}

    The field specifies the pattern to remove entries from running-config while "unset" operation and the identifier of unique command while "set" operation.该字段指定了在“unset”操作时从running-config中删除条目的模式,以及在“set”操作时唯一命令的标识符。

    The default is the name of the current command (${__cmd}).默认值为当前命令的名称( ${__cmd} )。

    [file] {#CONFIG_file}

    This field defines the filename to dump running-config to.这个字段定义了转储运行配置的文件名。

    [splitter] {#CONFIG_splitter}

    A boolean flag. The allowed values is true or false. If the "splitter" is "true" than the current command will be separated with the "!" symbol within its configuration group. See the "priority" description for details about configuration groups.一个布尔标志。允许的值是true或false。如果“splitter”是“true”那么当前命令将在其配置组中用“!”符号分隔。有关配置组的详细信息,请参阅“priority”描述。

    Default is true. 默认值为true。

    [sequence] {#CONFIG_sequence}

    [unique] {#CONFIG_unique}

    [depth] {#CONFIG_depth}

    The CISCO-like config supports nested commands. It uses indention as a syntax for the nesting. To specify nesting depth of command the "depth" option of its [VIEW] tag is used. All the commands of view have the same depth.类似于CISCO的配置支持嵌套命令。它使用缩进作为嵌套的语法。要指定命令的嵌套深度,使用其[VIEW]标签的“depth”选项。视图的所有命令具有相同的深度。

    VAR 哪里

    This tag may be used within the global scope. The tag defines the Klish's internal variable. The variable can be used like syntax ${var_name}. The variables can be static i.e. their values is expanded once. Or variable can be dynamic i.e. the value will be expanded each time this variable is used.这个标签可以在全局作用域内使用。标签定义了Klish的内部变量。变量可以像语法 ${var_name} 一样使用。变量可以是静态的,即它们的值只扩展一次。或者变量可以是动态的,即每次使用这个变量时,它的值都会被扩展。

    The VIEW tag can contain the following tags:VIEW标签可以包含以下标签:

  • [ACTION] - once [动作]-一次
  • name {#VAR_name} 名字{# VAR_name}

    [help] {#VAR_help} 【帮助】{# VAR_help}

    [value] {#VAR_value}

    [dynamic] {#VAR_dynamic}

    WATCHDOG 监管机构

    This tag may be used within the global scope. The WATCHDOG tag is used to recover system after errors.

    The VIEW tag can contain the following tags:VIEW标签可以包含以下标签:

  • [ACTION] - once [动作]-一次
  • HOTKEY 热键

    This tag may be used within the global scope and within the scope of a [VIEW] element. The HOTKEY tag allows to implement programmable hotkeys. The global view (XML configuration without explicit view definition) and [VIEW] can contain HOTKEY tags. See [hotkeys] section for additional information.

    The HOTKEY tag was implemented since klish-1.5.7 and klish-1.6.2.

    key {#HOTKEY_key} 关键{# HOTKEY_key}

    The symbolic key description. The Klish supports control keys with "Ctrl" ("^" symbol) only. Some combination are internally reserved (like a Ctrl^C and some other keys). To define a key use "^key_symbol". For example:

    <HOTKEY key="^Z" .../>
    <HOTKEY key="^S" .../>

    The first line is for Ctrl^Z and the second is for Ctrl^S combinations accordingly.

    cmd {#HOTKEY_cmd}

    The Klish [COMMAND] with arguments to execute on specified hotkey combination. This command must be defined in XML config. The command string can contain dynamically expanded [VAR]s.

        <HOTKEY key="^Z" cmd="exit"/>
        <HOTKEY key="^@" cmd="show running-config"/>
        <HOTKEY key="^S" cmd="echo ${HOSTNAME}"/>
        <VAR name="HOSTNAME" ... />

    PLUGIN 插件

    name {#PLUGIN_name} 名字{# PLUGIN_name}

    [alias] {#PLUGIN_alias}

    [file] {#PLUGIN_file}

    HOOK 钩

    name {#HOOK_name} 名字{# HOOK_name参数}

  • init
  • fini
  • access
  • config
  • log
  • [builtin] {#HOOK_builtin}

    Utilities实用程序

    clish {#utility_clish}

    Command line interface shell.

    Synopsis语法

    $ clish [options] [script_filename]

    Description 描述

    The clish is command line interface shell. The available shell commands and its actions are defined by XML configuration files. The clish utility can get input commands from terminal in interactive mode, from files specified in command line (multiple "script_filename" arguments) or standard input.

    Options选项参数

    -v, --version

    Print the version of clish utility.

    -h, --help

    Print help. 打印帮助。

    -s <path>, --socket=<path>

    The clish utility can work together with the konfd daemon. This daemon can store commands entered in clish. It's useful to implement config file like CISCO's running-config that stores current system configuration i.e. sequence of commands to achieve current system state. The command sequence can be saved to file (CISCO's startup-config) and executed in batch(分批) mode later by clish utility.

    守护进程konfd可以保存clish的命令。这个很有用用于执行配置文件像CISCO的running-config,保存了当前系统的配置。这样,一系列的命令可以达到系统状态。这些命令序列可以保存到文件(CICSO的startup-config)并过后执行到分批模式通过clish程序。

    The [daemon listens for connections on UNIX domain socket. You can specify the filesystem path to this UNIX domain socket to connect to.

    守护程序监听socket。可以分文件系统

    -l, --lockless

    Don't use locking mechanism.

    -e, --stop-on-error

    Stop programm execution on error.

    -b, --background

    Start shell using non-interactive mode.

    -q, --quiet

    Disable echo while executing commands from the file stream.

    -d, --dry-run

    Don't actually execute ACTION scripts.

    -x <path>, --xml-path=<path>

    Path to XML scheme files.

    -w <view_name>, --view=<view_name>

    Set the startup view.

    -i <vars>, --viewid=<vars>

    Set the startup viewid.

    -u, --utf8

    Force UTF-8 encoding.

    -8, --8bit

    Force 8-bit encoding.

    -o, --log

    Enable command logging to syslog's local0.

    Environment 环境

    CLISH_VIEW

    User can define CLISH_VIEW environment variable to set initial view. This value will be used instead of the initial view from STARTUP tag.

    The feature is available starting with klish-1.1.0.

    CLISH_VIEWID

    The CLISH_VIEWID environment variable can redefine the viewid field from STARTUP tag.

    The feature is available starting with klish-1.1.0.

    Files 文件

    Return codes 返回代码

    The clish utility can return the following codes:

  • 0 - OK
  • 1 - Unknown internal error.
  • 2 - IO error. Can't find stdin for example.
  • 3 - Error while the ACTION script execution.
  • 4 - Syntax error.
  • 255 - The system error like wrong command line option for clish utility.
  • Notes 笔记

    The return codes are available since klish-1.5.2 or SVN's revision #516.

    konfd {#utility_konfd} confd {#utility_confd}

    The konfd is a daemon(守护程序) to store current running-config. You can consider running-config as a current system settings or as a list of commands that have been executed for now by the user or automatically (by the script).

    The name "konfd" is used since klish-1.1.0. The earlier versions use name "confd" for the configuration daemon.

    The running-config 的running-config

    Generally the running-config consists of the the arbitrary(任意的) text lines. Each entry may contain another nested(嵌套) text lines. Note the konfd knows nothing about Klish commands and Klish syntax. The commands is just a text strings for the konfd. It's important to realize. The example of running-config:

    hostname Router
    !
    interface ethernet 0
     ip address 192.168.1.1/24
     enable
    !
    interface ethernet 1
     ip address 10.0.0.1

    The "hostname Router" entry has no nested entries. The "interface ethernet 0" and "interface ethernet 1" contain nested entries.

    Comments注释

    The "!" symbol is a comment for the Klish. Each line starting with the "!" consider as a comment so this line will be ignored by the Klish. The konfd daemon can output a current state of running-config. The previous text is an example of such output. Generally the comments are not really stored by the konfd. The konfd automatically inserts "!" between first level running-config entries for more human readable view.

    Path 路径

    The running-config structure can be considered as a filesystem-like structure. The "interface ethernet 0" entry can be considered as a directory with the nested "files". So each entry has a "path". The first level entries have an empty path but the nested entries like a "enable" entry has a non-empty path: "interface ethernet 0" The running-config can contain multi level nesting: interface ethernet 0 ip address 192.168.1.1/24 ip options mtu 1500 enable In this case the "mtu 1500" entry has a following path: "interface ethernet 0" "ip options" The "path" concept is important for running-config entries manipulations.

    Priority 优先级

    Each entry has a priority. The priority is a 16-bit unsigned integer. The entries with minimal priority resides on the begining of the running-config. The default priority is "0". The entries with the same priority will be ordered alphabetically.

    The priority can be specified in hex format. The Klish use "0x7f00" default value for the priority if priority is not specified explicitly within [CONFIG] tag. The "0x7f00" is a middle of the possible priority range.

    The high and low bytes within priority value have a little different meanings. The first level entries with different high bytes will be splitted by "!" (comment sign) always. By default the entries with equal high byte and arbitrary low byte will be splitted by "!" too. But if the entry has a "non-split" flag (see konfd protocol description to find out how to set this flag) the "!" will not be inserted before current entry if previous entry has the same high byte. So the entries can be grouped and don't be splitted by the "!".

    The high and low bytes within priority value have no special meanings for nested entries.

    Sequences 序列

    The konfd supports ordered lists a.k.a. "sequences". The entry can be or not to be a part of the sequence. It can be specified by a special options while entry creation. All entries in sequence must have the same priority value. The priority can be considered as an identifier of the sequence. The running-config can contain many sequences at the same time. The sequences will be identified by the priority value.

    The new entry can be inserted into sequence with specified sequence number. The entry can be removed from the sequence by its sequence number.

    The konfd can output entries without or with sequence numbers prepending the entry value.

    See the konfd communication protocol description for detail about sequence using.

    Communicate to konfd daemon与konfd守护进程通信

    The konfd daemon is accessible via UNIX socket interface. The socket path can be specified via command line. So it's possible to have a several konfd executed simultaneously. The default socket path is /tmp/konfd.socket.

    The konfd uses text based protocol for communication with another processes. The syntax of protocol is like a command line with options. It will be documented later in this document.

    Options 选项

    -v, --version

    Print the version of clish utility.

    -h, --help

    Print help. 打印帮助。

    -d, --debug

    Enable debug mode. Don't daemonize konfd.

    -s <path>, --socket=<path>

    Specify the UNIX socket filesystem path to listen on.

    -p <path>, --pid=<path>

    File to save daemon's PID to.

    -r <path>, --chroot=<path>

    Path to chroot to. Used for security reasons.

    -u <user>, --user=<user>

    Execute daemon as specified user.

    -g <group>, --group=<group>

    Execute process as specified group.

    The konfd protocol 1.3.2 konfd协议

    The syntax of protocol is like a command line with options. The actions and options are specified by the arguments prepend with "-" or "--" (for long options) and after all arguments the "path" is specified. Each element of path must be quoted. Firstly the action must be specified:

    Add entry: -s, --set

    To add new entry to the running-config the "-s" or "--set" argument is used. The following arguments are mandatory for this action:

  • -l <string>, --line=<string>. This argument defines the text line to add to the running-config.
  • -r <regexp>, --pattern=<regexp>. This argument contain extended regular expression and defines unique part of the entry i.e. the existing entries matching this pattern will be removed before new entry creation.
  • The path to store new entry. This argument can be empty if entry must be added to the first level.
  • Examples: -s -l "interface ethernet 0" -r "^interface ethernet 0$" This example will add new entry "interface ethernet 0" to the first level of the running-config. If the entry "interface ethernet 0" already exists it will be overwritten by the same entry. The definitions of another interfaces (with another interface numbers) will not be removed because the regular expression contain the number "0" at the end of the pattern.

    -s -l "ip address 192.168.0.1/24" -r "^ip address " "interface ethernet 0" This example will add new nested entry "ip address 192.168.0.1/24" to the "interface ethernet 0" path. If the IP-address was defined before this action the old entry matching the "^ip address " pattern will be replaced by the new address. Suppose the entry "interface ethernet 0" already exists. -s -l "mtu 1500" -r "^mtu " "interface ethernet 0" "ip options" This code will add "mtu 1500" nested entry to the path "interface ethernet 0" "ip options". Suppose the path entries already exist. The running-config output after this operation is: interface ethernet 0 ip options mtu 1500

    konf {#utility_konf} conf {#utility_conf}

    sigexec {#utility_sigexec}

    Synopsis 剧情简介

    $ sigexec <command to execute>

    Description 描述

    The sigexec utility unblocks (by sigprocmask()) all signals and executes specified command. It's useful within atomic_action non-interruptable [ACTION] scripts for daemon starting. The daemon will have clean signal mask.

    Options 选项

    -v, --version

    Print the version of utility.

    -h, --help

    Print help. 打印帮助。

    Build 构建

    The buildroot environmentbuildroot环境

    Buildroot is a set of Makefiles and patches that makes it easy to generate a complete embedded Linux system. See the http://www.buildroot.net/ for the details. The Klish can be used as the "package" with the buildroot environment to get into the buildroot's target embedded system.Buildroot是一套Makefiles和补丁,可以很容易地生成一个完整的嵌入式Linux系统。详情请参阅http://www.buildroot.net/。Klish可以作为“包”使用buildroot环境,以进入buildroot的目标嵌入式系统。

    The Klish source tree contain the contrib/buildroot directory with the files to embed the Klish package into the buildroot environment. The contrib/buildroot/package/klish must be copied to the buildroot's source tree package/klish directory. Then the package/Config.in file must be changed. Add the following lineKlish源码树包含了contrib/buildroot目录,其中包含了将Klish包嵌入到buildroot环境中的文件。contrib/buildroot/package/klish必须被复制到buildroot的源码树package/klish目录中。然后必须修改package/Config.in文件。添加以下行

    source "package/klish/Config.in"源文件 "package/klish/Config.in"

    to the section started with 'menu "Shell and utilities"' (or to the another section if you think it will be better and you know what you do). After that you can configure buildroot and enable the building the Klish package. You can find the menu for the Klish within "Package Selection for the target"->"Shell and utilities" in the configurator. The Klish's config allow to use the predefined version of Klish or automatically download the last revision from the SVN repository.到“菜单“Shell 和实用工具””开始的部分(或者到另一个部分,如果你认为它会更好,你知道你在做什么)。之后,你可以配置buildroot并启用构建Klish包。你可以在配置器中的“目标的包选择”->“Shell 和实用工具”中找到Klish的菜单。Klish的配置允许使用预定义版本的Klish或自动从SVN存储库下载最新的修订版。

    These files were tested with buildroot-2010.11. The current predefined stable version of Klish package that used in the buildroot's klish.mk file is 1.3.1.这些文件是用buildroot-2010.11测试的。 当前预定义的稳定版本的Klish包,用于在buildroot的klish.mk文件是1.3.1。

    XML backends(后端)

    Supported XML backends 支持的 XML 后端

    The Klish engine uses external (since version klish-1.6.0) XML backends to parse XML config files. Now Klish supports three XML backends:

  • libxml2
  • expat 外籍人士
  • libroxml 库文件
  • There are XML tests in xml-examples/test directory in Klish sourcecode tree. These tests contain some typical cases that can lead to XML backend errors.

    You can specify preferred XML backend by project configure script argument:

  • --with-libxml2 for using libxml2
  • --with-libexpat for using expat
  • --with-libroxml for using libroxml
  • The following table is a comparision of supported XML engines. The values are not pecise but the table is useful to estimate the main parameters of engines.

    EngineStripped size, KbytesExecution time, s
    libxml214620.180
    expat 外籍人士1700.230
    libroxml 库文件520.620

    The first column is an engine name. The second column is a size of stripped library (shared object). The third one is a time of execution clish compiled with correspondent engine. The clish was executed like this:

    $ time clish -x /etc/clish -c "exit" --dry-run

    Note this command lead to immediate exit after loading XML configuration files. The tests show the most loading time clish spend to load XMLs because the load time with tiny XMLs is something like 0.002s - 0.005s. I have used a huge XML set for the tests. The size of XMLs is 2145 Kbytes.

    So you can see the larger engines have better execution times. And the slower engines are smaller.

    libxml2

    The libxml2 project homepage is [The tested versions are:

    2.7.8

    The klish-1.6.0 tests are passed on:

  • Linux (ArchLinux)
  • FreeBSD 8.2
  • expat 外籍人士

    The expat project homepage is http://expat.sourceforge.net/. The tested versions are:

    2.0.1

    The klish-1.6.0 tests are passed on:

  • Solaris 11
  • FreeBSD 8.2
  • 2.1.0

    The klish-1.6.0 tests are passed on:

  • Linux (ArchLinux)
  • libroxml 库文件

    The expat project homepage is [Don't use versions earlier than libroxml-2.2.0. The tested versions are:

    2.1.1

    The klish-1.6.0 test are passed.

  • FreeBSD 8.2 Probably the recent version of libroxml can be build on this systems.
  • 2.2.0

    The klish-1.6.0 tests are NOT passed. The "test5" is failed (broken quotes within comment). Now libroxml git repository contain the patch to solve this problem. It was tested on:

  • Linux (ArchLinux)
  • # show ip route   #显示IP路由
    default via 192.168.122.1 dev ens12 proto static onlink

    ip route ip路由

    作用

    格式

    (config)# ip route 1.1.0.1 ethernet 1
    (config)# no ip route   (config)# ip route 设置路由

    ip default-gateway ip默认网关

    作用

    格式

    (config)# ip default-gateway 1.1.0.0
    (config)# no ip default-gateway

    ip routing ip路由

    作用

    格式

    (config)# ip routing   (config)# ip route 路由
    (config)# no ip routing

    throttling 节流

    作用

    格式

    throttling ( recv | send ) rate <num=1:10>

    ip pool ip池

    作用

    格式

    (config)# set-ip-pool mypool ipv4 1.1.0.1 1.1.0.254(config)# add-ipv4 ipv4 1.1.0.1 1.1.0.254

    show list 显示列表

    作用

    格式

    # show list all   #全部显示列表
      -s -l "ip address 192.168.0.1/24" -r "^ip address " "interface ethernet 0"   这个例子将添加新的嵌套条目“ip address 192.168.0.1/24”到“interface ethernet 0”路径中。如果IP地址在该操作之前已经定义,那么匹配“^ip address”模式的旧条目将被新地址替换。假设“interface ethernet 0”条目已经存在。   -s -l "mtu 1500" -r "^mtu " "interface ethernet 0" "ip options"   这段代码将添加“mtu 1500”嵌套条目到“interface ethernet 0”“ip options”路径中。假设该路径条目已经存在。该操作后的running-config输出为:   interface ethernet 0 ip options mtu 1500  

    Legacy backend 旧的后端

    The Klish earlier than klish-1.6.0 version uses internal implementation of http://sourceforge.net/projects/tinyxml/ tinyXML engine. It was frozen snapshot and it was rather good but tinyXML is written in C++. So Klish can't be build without C++. It's not good for embedded devices. The klish-1.6.0 and later versions can be build without C++.

    FreeBSD note FreeBSD注意

    The FreeBSD use "ports" system for third party open source projects. All ports are installed to /usr/local. So the Klish configuration with installed XML backends is something like this:

    $ CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure --with-libxml2

    Solaris note Solaris注意

    The Solaris 11 has no pkg-config package. The configure script use pkg-config to search for libxml2 headers and libs. So to build Klish with libxml2 backend you need to configure libxml2 path manually:

    $ ./configure --with-libxml2=/usr

    HOWTO 基本知识的

    The XML files validation 生效XML文件验证生效

    The XML files can be validated by the xmllint utility.XML文件可以由xmllint实用程序进行验证。

    XML文件可以通过xmllint程序生效

    $ xmllint --noout --schema <schema_filename>.xsd <xml_filename>.xml

    Or you can validate all XML file in the specified dir:或者你可以验证指定目录下的所有 XML 文件:

    也可以指定整个目录生效

    $ xmllint --noout --schema <schema_filename>.xsd <xml_dir>/*.xml

    Static build 静态构建

    To build Klish statically use:要静态构建 Klish,请使用:

    $ ./configure --disable-shared$./configure --disable-shared 禁用共享
    $ make LDFLAGS+="-all-static"将LDFLAGS设置为"-all-static"

    The LDFLAGS is global so shared libraries can't be build and building of shared libraries must be disabled.LDFLAGS 是全局的,所以不能构建共享库,必须禁用共享库的构建。

    Leak of dlopen() 泄漏的dlopen()

    If target system doesn't support dlopen() then configure script will configure building process to don't use dlopen() (and other dl functions) but link to plugin's shared objects.如果目标系统不支持dlopen(),那么配置脚本将配置构建过程,以便不使用dlopen()(和其他dl函数),而是链接到插件的共享对象。

    If you need to link statically with plugins use:如果你需要静态链接插件,请使用:

    $ ac_cv_header_dlfcn_h=no ./configure --prefix=/usr --with-lua --disable-shared
    $ make LDFLAGS+="-all-static"将LDFLAGS设置为"-all-static"

    Glibc's NSS NSS Glibc的

    The standard glibc uses dlopen() to implement getpwnam()-like and some other functions. The cause is NSS engine. It allows to use different backends (like LDAP, NIS. etc) for name resolution. The implementations of backends are in the separate shared objects. So NSS-depended functions can't be statically linked in common case (note glibc can be build with special option to enable NSS static linkage).

    The klish configure script has a special option --disable-nss to don't use standard NSS functions. The functions like getpwnam() will simulate standard behaviour. In this mode functions can't resolve user/group names but take only the numbers like '0' for root. But klish can be build fully statically in this mode. Implemented since klish-2.2.3.klish配置脚本有一个特殊的选项 --disable-nss ,它可以不使用标准的NSS函数。像getpwnam()这样的函数将模拟标准的行为。在这种模式下,函数不能解析用户/组名,但只接受数字,比如“0”作为root。但是klish可以在这种模式下完全静态地构建。

    XML examples测试用例

    The Klish source tree contain the Klish specific XML examples that show the basic CISCO-like (not exactly copy) interface to configure network interfaces and routing on Linux system. You can find it in xml-examples/klish dir in the Klish source tree.Klish源码树包含了Klish特定的XML示例,这些示例展示了基本的类似于思科(不完全是复制)的接口,用于在Linux系统上配置网络接口和路由。

    The original clish examples is also available and workable. You can find it in xml-examples/clish dir.原始的 clish 示例也是可用的,可以在 xml-examples/clish 目录下找到。

    The KLISH specific examples 特有用例

    The Klish has some new features that is not supported in clish. So the Klish specific examples show some of these new features. The dir xml-examples/klish is more complex than clish examples dir. That is needed to show CISCO-like 'enable' command that allow to get privileged mode and execute administration commands.Klish有一些新特性是clish不支持的,所以Klish的特定示例展示了这些新特性,dir xml-examples/klish比clish examples dir更复杂,它需要显示类似CISCO的“enable”命令,该命令允许获得特权模式并执行管理命令。

    The 'enable' command implementation'enable' 命令实现

    The 'enable' command is implemented by using 'su' linux command and executing new clish instance. It's the right way to get privilegies because the clish/Klish is not enough tool to distribute system permissions. When the 'su -c clish' is used the operation system is responsible to permit or deny some system operations to the current user. For example unprivileged user cannot change the network interfaces settings and routing table. So if even the unprivileged user will be able to enter network specific commands in Klish the system will deny his commands.'enable'命令是通过使用'su'linux命令和执行新的clish实例来实现的。这是获得特权的正确方法,因为clish/Klish是不足以分配系统权限的工具。当使用'su -c clish'时,操作系统负责允许或拒绝对当前用户的一些系统操作。例如,非特权用户不能更改网络接口设置和路由表。因此,即使非特权用户能够在Klish中输入特定于网络的命令,系统也会拒绝他的命令。

    If the some kind of role model is needed the 'su' command can be used to became non-root user with additional permissions. The additional permissions can be set using 'sudo' for example.如果需要某种角色模型,可以使用'su' 命令成为具有额外权限的非 root 用户,例如,可以使用'sudo' 设置额外权限。

    Directory structure目录结构

    The directory structure resulting from the realization of 'enable' command. The privileged and unprivileged users must have the different set of XML files. The example suppose that Klish was configured with './configure --prefix=/usr' so the installed clish binary will be located in /usr/bin dir. The 'etc' dir of the example must be copied to the / dir to the target system.enable命令实现的目录结构. 特权用户和非特权用户必须有不同的XML文件集. 例如,假设Klish是用'./configure --prefix=/usr'配置的,那么安装的clish二进制文件将位于/usr/bin目录下. 例子中的'etc'目录必须复制到目标系统的/目录下.

    用例假设编译时'./configure --prefix=/usr',这样clish bin文件就安装到了/usr/bin目录。用例中的'etc'目录需要拷贝到系统的目标路径。

    The etc/ dir contain clish/ clish-enable/ and clish-xml/ dirs. The clish-xml/ dir contain the all (privileged and unprivileged) XMLs. The clish/ dir contain symbolic links to the ../clish-xml/<name>.xml files that is needed in non-privileged mode. The clish-enable/ dir contain symbolic links to the ../clish-xml/<name>.xml files that is needed in privileged mode.

    etc目录下一级包含 clish/ clish-enable/ clish-xml/。clish-xml/目录包含所有(特权和非特权)xmls文件。 clish/目录包好符号链接到../clish-xml/<name>.xml 文件需要非特权模式。clish-enable/ 目录包含符号链接到../clish-xml/<name>.xml需要特权模式(就是enable模式)。

    The etc/ also contain init.d/klish-init script that will init Klish subsystem on the boot(计算机启动) time. It starts the konfd daemon that will store all the configuration (all the configuration commands user will enter). Then the saved configuration file /etc/startup-config is executed via Klish to restore previous (pre-reboot) system configuration. The init.d/klish-init script can be included in some init script like rc.local so it will be executed automatically on system startup.

    etc/目录也包含 init.d/klish-init脚本,可以初始化klish子系统在启动时。它开始konfd守护程序将会保存所有配置(所有用户输入的配置命令)。保存的配置文件/etc/startup-config执行通过klish保存之前(预重启)系统配置。init.d/klish-init脚本可以包括到一些初始化脚本里如rc.local可以自动执行在系统启动时。

    启动时执行startup-config里的命令

    CLISH_PATH=xml-examples/klish/etc/clish-enable bin/clish /etc/startup-config
                                                   [bin文件]  [启动时命令行脚本]

    startup-config文件

    # cat /etc/startup-config
    show ip route   显示IP路由

    测试

    /klish# CLISH_PATH=xml-examples/klish/etc/clish-enable bin/clish  /etc/startup-config
    # show ip route   #显示IP路由
    default via 192.168.122.1 dev ens12 proto dhcp src 192.168.122.226 metric 100默认通过192.168.122.1 设备ens12 初始化dhcp源192.168.122.226 度量100

    The testing purposes only仅供测试用途

    If you don't want to install all Klish infrastructure to your system and don't want to use 'enable' command you can use the following commands to see the ability of unprivileged and privileged examples (suppose the current dir is a Klish source tree):如果你不想安装所有的Klish基础设施到你的系统,也不想使用'enable'命令,你可以使用以下命令来查看unprivileged和privileged的例子的能力(假设当前目录是Klish源代码树):

    启动时选择特权/非特权模式

    ~/klish$ CLISH_PATH=xml-examples/klish/etc/clish bin/clish
    ~/klish$ CLISH_PATH=xml-examples/klish/etc/clish-enable bin/clish

    Note privileged commands can be entered by the common user but the real system commands execution will be denied.注意,普通用户可以输入特权命令,但实际的系统命令执行将被拒绝。

    The CLISH original examples原始用例

    To test Klish over the clish original examples the project must be configured and built. Unarchive the source code tarball and 'cd' to the klish-<version> tree. Then execute the following commands:要想在clish的原例子上测试Klish,必须先配置和构建项目,解压源代码tarball文件,然后切换到klish- <version> 树,然后执行以下命令:

    $ ./configure   美元。/配置
    $ make   让美元
    $ CLISH_PATH=xml-examples/clish bin/clish

    命令汇总

    exit 退出

    作用

    退出当前模式

    格式

    (config)# exit   (配置)#退出
    #

    configure terminal 配置终端

    作用

    进入config模式

    格式

    # configure terminal   # 配置终端
    Password is '123456': 123456密码是'123456':123456
    
    (config)#   (配置)#

    show startup-config 显示startup-config

    作用

    格式

    # show startup-config   # 显示启动配置

    show running-config 显示running-config

    作用

    格式

    # show running-config

    copy running-config 复制running-config

    作用

    格式

    # copy running-config startup-config

    show diag 显示诊断接头

    作用

    显示网卡

    格式

    # show diag
    00:0c.0 Ethernet controller: Red Hat, Inc. Virtio network device

    show interfaces 显示接口

    作用

    显示网口

    格式

    # show interfaces
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever

    show ip route 显示IP路由

    作用

    显示路由表

    格式

  • 16
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值