本文记录的是关于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

本文记录的是如何使用Gson序列化和反序列化包含不同类型对象的 JSON Array,例如:

1
['hello',5,{name:'GREETINGS',source:'guest'}]

对于这种情况看,使用 Gson toJson(collection) 序列化,无需做额外的工作都能够得到正确的结果,但是,使用 fromJson(json, Collection.class) 反序列化时不能得到期望结果,因为Gson不知道如何将集合中元素与其类型对应起来。可采用如下解决方法: 使用Gson parser API(JsonParser)解析数组中每个元素,然后对数组中每个元素使用Gson.fromJson()进行反序列化。示例如下:

Continue reading

本文记录的是使用Gson如何序列化和反序列化实体中部分属性,有两种方式,使用transient和使用注解@Expose.

默认情况下,如果使用transient标注属性,那个该属性在序列化和反序列化时就会被屏蔽。同样地,如果属性声明为static类型,那么该属性也会被屏蔽. 如下示例所示:

Student对象:

1
2
3
4
5
6
7
public class Student {
private int stuNo;
private transient int sex;
private String name;

//......
}
Continue reading

本文记录的是如何使用Gson处理List对象数据, 包括序列化List对象以及将Json串反序列化为List对象.

首先定义一个Student类, 其属性都是基本类型, 如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Student {
private int stuNo;
private int sex;
private String name;
public Student() {
}

public Student(int stuNo, int sex, String name) {
this.stuNo = stuNo;
this.sex = sex;
this.name = name;
}
//getter & setter
......
}
Continue reading

本文记录的是如何使用Gson处理Array类型数据, 包括将Array对象序列化为Json串以及将Json串反序列化为Array对象.

下面的示例是将数组元素序列化为Json串,如下所示:

Serialization:

1
2
3
4
5
Gson gson = new Gson();
int[] ints = {1, 2, 3, 4, 5};
String[] strings = {"abc", "def", "ghi"};
System.out.println("json_string: " + gson.toJson(ints));
System.out.println("json_string: " + gson.toJson(strings));
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
Author's picture

CaryaLiu

@Chengdu


iOS Developer


Chengdu