ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

hualinux ros 1.17:RouterOS脚本(七):命令

2020-11-25 22:00:39  阅读:397  来源: 互联网

标签:hualinux 1.17 菜单 命令 打印 RouterOS put variable print


目录

一、全局命令

二、菜单级命令

2.1 常用菜单命令

2.2 import导入

2.3 打印参数


本章继续讲ros脚本 ,内容为命令,ros命令分2种

  • 全局命令:即在整个ros中都有效的。每个全局命令都应以“:”标记开头,否则将被视为变量。
  • 菜单命令:登录winbox以菜单方式操作的命令,一般顶级菜单建议用"/"开头,不写也不会报错。

一、全局命令

即在整个ros中都有效的。每个全局命令都应以“:”标记开头,否则将被视为变量。全局命令列表如下:

命令语法说明例子
/ 

go to root menu

根菜单

 
.. 

go back by one menu level

返回上一级

 
? 

list all available menu commands and brief descriptions

帮助

 
global:global <var> [<value>]

define global variable

全局变量

:global myVar "something"; :put $myVar;
local:local <var> [<value>]

define local variable

局部变量/本地变量

{ :local myLocalVar "I am local"; :put $myVar; }
beep:beep <freq> <length>

beep built in speaker

内置扬声器的哔哔声

 
delay:delay <time>

do nothing for a given period of time

延迟操作,时间单位为秒

{:delay 5;:put "5 second"}
 
put:put <expression>

put supplied argument to console

输出控制台


 
len:len <expression>

return string length or array element count

返回字符串长度

:put [:len "length=8"];
typeof:typeof <var>

return data type of variable

返回变量数据类型

:put [:typeof 4];
pick:pick <var> <start>[<end>]

return range of elements or substring. If end position is not specified, will return only one element from an array.

返回指定范围的元素或子字符串,如果未指定结束位置,则将仅返回数组中的一个元素。

:put [:pick "abcde" 1 3]
log:log <topic> <message>

write message to system log. Available topics are "debug, error, info and warning"

将消息写入系统日志。 可用主题为“调试,错误,信息和警告”

:log info "Hello from script";
time:time <expression>

return interval of time needed to execute command

返回执行命令所需的时间间隔

:put [:time {:for i from=1 to=10 do={ :delay 100ms }}];
set:set <var> [<value>]

assign value to declared variable.

设置变量的值

:global a; :set a true;
find:find <arg> <arg> <start>

return position of substring or array element

返回子字符串或数组元素的位置

:put [:find "abc" "a" -1];
environment:environment print <start>

print initialized variable information

打印初始化变量信息

:global myVar true; :environment print;
terminal 

terminal related commands

终端相关命令

 
error:error <output>

Generate console error and stop executing the script

生成控制台错误并停止执行脚本

 
execute:execute <expression>

Execute the script in background. Result can be written in file by setting file parameter.

在后台执行脚本。 可以通过设置文件参数将结果写入文件中。

{
:local j [:execute {/interface print follow where [:log info ~Sname~]}];
:delay 10s;
:do { /system script job remove $j } on-error={}
}
parse:parse <expression>

parse string and return parsed console commands. Can be used as function.

解析字符串并返回已解析的控制台命令。能作为函数使用。

:global myFunc [:parse ":put hello!"];
$myFunc;
resolve:resolve <arg>

return IP address of given DNS name

返回给定DNS名称的IP地址

:put [:resolve "www.mikrotik.com"];
toarray:toarray <var>

convert variable to array

将变量转换为数组

 
tobool:tobool <var>

convert variable to boolean

将变量转换为布尔值

 
toid:toid <var>

convert variable to internal ID

将变量转换为内部ID

 
toip:toip <var>

convert variable to IP address

将变量转换为IP地址

 
toip6:toip6 <var>

convert variable to IPv6 address

将变量转换为IPv6地址

 
tonum:tonum <var>

convert variable to integer

将变量转换为整数

 
tostr:tostr <var>

convert variable to string

将变量转换为字符串

 
totime:totime <var>

convert variable to time

将变量转换为时间

 
使用频率比较高的有:/ .. ?  global  local  put find  tonum tostr 

上面这些全局变量不用死记的,了解一下有那些功能,当你编写脚本的时候,想起有这么一个功能在全局变量中有,那么你就回找这个表就行了。

二、菜单级命令

登录winbox以菜单方式操作的命令,一般顶级菜单建议用"/"开头,不写也不会报错。

2.1 常用菜单命令

大多数子菜单中都有以下命令:

命令语法说明
addadd <param>=<value>..<param>=<value>

add new item

添加一个新项

removeremove <id>

remove selected item

删除所选项

enableenable <id>

enable selected item

启用所选项

disabledisable <id>

disable selected item

禁用所选项

setset <id> <param>=<value>..<param>=<value>

change selected items parameter, more than one parameter can be specified at the time. Parameter can be unset by specifying '!' before parameter.

更改所选项目的参数,一次可以指定多个参数。 可以通过指定“!”来取消设置参数 在参数之前。

Example:
/ip firewall filter add chain=blah action=accept protocol=tcp port=123 nth=4,2
print
set 0 !port chain=blah2 !nth protocol=udp

getget <id> <param>=<value>

get selected items parameter value

获取所选项参数值

printprint <param><param>=[<value>]

print menu items. Output depends on print parameters specified. Most common print parameters are described here

打印菜单项。 输出取决于指定的打印参数。 此处介绍了最常用的打印参数

exportexport [file=<value>]

export configuration from current menu and its sub-menus (if present). If file parameter is specified output will be written to file with extension '.rsc', otherwise output will be printed to console. Exported commands can be imported by import command

从当前菜单及其子菜单(如果有)中导出配置。 如果指定了file参数,则输出将被写入扩展名为“ .rsc”的文件,否则输出将被打印到控制台。 导出的命令可以通过import命令导入

editedit <id> <param>

edit selected items property in built-in text editor

在内置文本编辑器中编辑选定的项目属性

findfind <expression>

Returns list of internal numbers for items that are matched by given expression. For example:  :put [/interface find name~"ether"]

返回与给定表达式匹配的项的内部编号列表。

上面的这些命令使用频率都很高,也不少,最好是多练习理解一下。

2.2 import导入

导入命令可从根菜单使用,用于从由export导出命令创建或手动编写的文件中导入配置。

2.3 打印参数

有几个参数可用于打印命令:

参数说明例子
append  
as-value

print output as an array of parameters and its values

以数组的方式打印

:put [/ip address print as-value]
brief

print brief description

打印摘要

 
detail

print detailed description, output is not as readable as brief output, but may be useful to view all parameters

打印详细,输出不如摘要的可读性,但可能有助于查看所有参数

 
count-only

print only count of menu items

打印菜单项数目

 
file

print output to file

打印输出到文件

 
follow

print all current entries and track new entries until ctrl-c is pressed, very useful when viewing log entries

打印所有当前条目并跟踪新条目,直到按ctrl-c为止,这在查看日志条目时非常有用

/log print follow
follow-only

print and track only new entries until ctrl-c is pressed, very useful when viewing log entries

仅打印和跟踪新条目,直到按ctrl-c为止,这在查看日志条目时非常有用

/log print follow-only
from

print parameters only from specified item

仅打印指定项目中的参数

/user print from=admin
interval

continuously print output in selected time interval, useful to track down changes where follow is not acceptable

在选定的时间间隔内连续打印输出,有助于跟踪不可接受的更改

/interface print interval=2
terse

show details in compact and machine friendly format

以紧凑和机器友好的格式显示细节

 
value-list

show values one per line (good for parsing purposes)

每行显示一个值(可用于解析)

 
without-paging

If output do not fit in console screen then do not stop, print all information in one piece

如果输出不适合控制台屏幕,则不要停止,将所有信息打印成一张

 
where

expressions followed by where parameter can be used to filter out matched entries

表达式,后跟where参数可用于过滤出匹配的条目

/ip route print where interface="ether1"

一次可以指定多个参数,例如 /ip route print count-only interval=1 where interface="ether1"

标签:hualinux,1.17,菜单,命令,打印,RouterOS,put,variable,print
来源: https://blog.csdn.net/hualinux/article/details/110121636

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有