创建扩展脚本后,可以在命令行上对其进行测试。 以下示例在 UNIX 系统上创建一个 OctetString 扩展,测试其输出,然后使用 SNMP 从脚本返回值。
测试脚本
#!/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。
extension 1 OctetString ReadWrite /opt/CA/SystemEDGE/debugext.sh
注意:该示例测试为 OctetString 的扩展脚本。 它对于 UNIX 操作系统有效。 在 Windows 系统上,必须在操作脚本命令中调用解释器。 例如,输入 perl.exe myscript.pl。
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。
./snmpset -c private -h 127.0.0.1 < myset.txt
./snmpget -c public -h 127.0.0.1 -o 1.3.6.1.4.1.546.14.1.0
./debugext.sh 1 SET debugSetString2
该命令应返回设置为输出的值。
./debugext.sh 1 GET
该命令应返回在前面的 SET 调用中设置的值。
|
版权所有 © 2013 CA。
保留所有权利。
|
|