本文记录的是shell之printf格式化输出.

首先看看其 man page 内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
NAME
printf -- formatted output

SYNOPSIS
printf format [arguments ...]

DESCRIPTION
The printf utility formats and prints its arguments, after
the first, under control of the format. The format is a character string which contains three types of objects: plain characters,
which are simply copied to standard output, character escape
sequences which are converted and copied to the standard
output, and format specifications, each of which causes printing
of the next successive argument.

The arguments after the first are treated as strings if the
corresponding format is either c, b or s;otherwise it is evaluated
as a C constant, with the following extensions:

o A leading plus or minus sign is allowed.
o If the leading character is a single or double quote, the value is the ASCII code of the next character.

从上述 man page 内容可以看出:

  1. printf通过format字符串格式化输出其后的arguments
  2. format字符串包含三种类型对象: 普通字符串,该对象输出时会直接拷贝到标准输出STDOUT;字符转义序列,通过字符转义之后输出到标准输出;格式说明符,每一个格式说明符对应输出相应的argument
  3. 如果对应的格式指示符是%c/%b/%s时,相对应的参数都视为字符串,否则它们会被解释为C语言的数字常量: 在其开头可使用正负号标识;如果字符串开头是单引号'或者双引号",那么打印输出的值是紧跟着单引号或者双引号后的那个字符的ASCII
Continue reading

本文记录的是关于shell之echo的知识。

echo是linux中常用的终端命令(command line),其包括:

1
command_name option argument

首先看看echo的 man page:

1
2
3
4
5
6
7
8
9
NAME
echo -- write arguments to the standard output

SYNOPSIS
echo [-n] [string ...]

DESCRIPTION
The echo utility writes any specified operands, separated by single blank (' ') characters and followed
by a newline (`\n') character, to the standard output.

从帮助文档可以看出:

  1. echo是将其后的arguments输出到(STDOUT),通常就是bash界面.
  2. echo是将所有的操作对象,以单一的空格` `分开的字符串,最后紧跟着换行符(''),输出到bash
Continue reading

本文记录的是在进行Net-SNMP配置及测试时经常用到的命令,具体的使用方法可参考命令的帮助文档。

####1. net-snmp-create-v3-user#### 正如命令的字面意思,该命令用来创建 Net-SNMP v3用户。

####2. net-snmp-config####

1
2
3
4
5
6
7
The net-snmp-config shell script is designed to retrieve the  
configuration information about the libraries and binaries dealing
with the Simple Network Management Protocol (SNMP), built from the
net-snmp source package. The information is particularily useful
for applications that need to link against the SNMP libraries and
hence must know about any other libraries that must be linked in
as well.

net-snmp-config命令用来获取处理SNMP协议的库和二进制文件的配置信息,其从Net-SNMP的源文件包编译而得。该信息对那些依赖于SNMP库的应用尤其有用.

Continue reading

本文记录是如何配置 Net-SNMP VACM. VACM,即 View Based Access Control.分为两部分: 1. VACM的快速配置 2. VACM的综合配置,该配置能够更加精细地配置用户的访问控制权限.

###一、VACM的快速配置###

####1. SNMPv1 and SNMPv2 rocommunity/rwcommunity#### 对于SNMPv1和SNMPv2c,对基于COMMUNITY的请求,能够将其访问权限限定在特定的OID树,且将访问来源限定在特定的IP访问内,通常采用如下格式:

1
2
3
4
rocommunity COMMUNITY [SOURCE [OID]]
rwcommunity COMMUNITY [SOURCE [OID]]
rocommunity6 COMMUNITY [SOURCE [OID]]
rwcommunity6 COMMUNITY [SOURCE [OID]]

对于SNMP 5.3及其以上的版本,该指示符也能够将其访问权限限定在特定的视图VIEW中,语法如下:

1
2
3
4
rocommunity COMMUNITY SOURCE -V VIEW
rwcommunity COMMUNITY SOURCE -V VIEW
rocommunity6 COMMUNITY SOURCE -V VIEW
rwcommunity6 COMMUNITY SOURCE -V VIEW
Continue reading

本文记录的是对 Net-SNMP 中 VACM mask 的理解,VACM 即 View Based Access Control 的缩写,其用于控制用户访问设备 MIB 树的权限。

在snmpd.conf 中使用 view 标识符加以 mask 参数,能够将用户的访问权限控制在 MIB Table 中的某一特定行,下面是 man page 中的摘要:

Continue reading

本文记录的是如何使用 64-bit 的mib计算Linux设备的存储大小。

为了解决snmp采集大容量(>2T)Linux设备时dskTotal越界的问题, 在snmp5.5+版本中引入了64bit的mibs, 包括 (UCD-SNMP-MIB::dskTotalLow,UCD-SNMP-MIB::dskTotalHigh),(UCD-SNMP-MIB::dskAvailLow,UCD-SNMP-MIB::dskAvailHigh),(UCD-SNMP-MIB::dskUsedLow,UCD-SNMP-MIB::dskUsedHigh), 那么如何利用64bit的mibs计算存储大小呢?

Continue reading

Linux下,如果想要删除目录及其子目录下某种类型文件,比如说所有的txt文件,则可以使用下面的命令:

find . -name "*.txt" -type f -print -exec rm -rf {} \;

. : 表示在当前目录下

-name "*.txt"

表示查找所有后缀为txt的文件

-type f

表示文件类型为一般正规文件

-print

表示将查询结果打印到屏幕上

-exec command

command为其他命令,-exec后可再接其他的命令来处理查找到的结果,上式中,{}表示”由find命令查找到的结果“,如上所示,find所查找到的结果放置到{}位置,-exec一直到\;是关键字,表示find额外命令的开始-exec到结束\;,这中间的就是find命令的额外命令,上式中就是 rm -rf

Comment and share

  • page 1 of 1
Author's picture

CaryaLiu

@Chengdu


iOS Developer


Chengdu