上一主题: 扩展脚本下一主题: 在管理软件中使用扩展变量


示例脚本测试

创建扩展脚本后,可以在命令行上对其进行测试。 以下示例在 UNIX 系统上创建一个 OctetString 扩展,测试其输出,然后使用 SNMP 从脚本返回值。

测试脚本

  1. 创建一个名为 /opt/CA/SystemEDGE/debugext.sh 的可执行文件,其中包含以下信息:
    #!/bin/sh
    Script=$0
    LeafNumber=$1
    Operation=$2
    SetValue=$3
    	
    if [ "$Operation" = "SET" ]; then
    echo $Script     > /tmp/debugext_set.txt 
    echo `date`      >> /tmp/debugext_set.txt
    echo $LeafNumber >> /tmp/debugext_set.txt
    echo $Operation  >> /tmp/debugext_set.txt
    echo $SetValue   >> /tmp/debugext_set.txt
    echo $SetValue   >  /tmp/debugext_setvalue.txt #SET VALUE HERE
    echo $SetValue   #You must echo back what was set
    fi
    	
    # Override GETNEXT and just do GET
    if [ "$Operation" = "GETNEXT" ];  then
    Operation="GET"
    fi
    	
    if [ "$Operation" = "GET" ]; then
    echo $Script     > /tmp/debugext_get.txt
    echo `date`      >> /tmp/debugext_get.txt
    echo $LeafNumber >> /tmp/debugext_get.txt
    echo $Operation  >> /tmp/debugext_get.txt
    if [ ! -f /tmp/debugext_setvalue.txt ]; then
    echo "ERROR: do set first... Script:$Script 
    LeafNumber:$LeafNumber Operation:$Operation"
    exit 0
    fi
    cat /tmp/debugext_setvalue.txt  #return SET VALUE
    fi
    

    注意:该示例测试为 OctetString 的扩展脚本。 它对于 UNIX 操作系统有效。 在 Windows 系统上,必须在操作脚本命令中调用解释器。 例如,输入 perl.exe myscript.pl。

  2. 在 sysedge.cf 中添加以下行:
    extension 1 OctetString ReadWrite /opt/CA/SystemEDGE/debugext.sh
    

    注意:该示例测试为 OctetString 的扩展脚本。 它对于 UNIX 操作系统有效。 在 Windows 系统上,必须在操作脚本命令中调用解释器。 例如,输入 perl.exe myscript.pl。

  3. 在命令行上输入以下内容来创建名为 myset.txt 的文件:
    echo "1.3.6.1.4.1.546.14.1.0 04 debugSetString" > myset.txt
    

    您现在有了名为 myset.txt 的文件。 希望将 OctetString(04) "debugSetString" 设置为 OID 1.3.6.1.4.1.546.14.1.0。

  4. 通过输入以下内容,发出 SNMP Set:
    ./snmpset -c private -h 127.0.0.1 < myset.txt
    
  5. 通过输入以下内容,检索 debugSetString 的值:
    ./snmpget -c public -h 127.0.0.1 -o 1.3.6.1.4.1.546.14.1.0
    
  6. 通过在命令行上输入以下内容,测试设置:
    ./debugext.sh 1 SET debugSetString2
    

    该命令应返回设置为输出的值。

    ./debugext.sh 1 GET
    

    该命令应返回在前面的 SET 调用中设置的值。