bash Net-snmp (get/walk) 的 shell 脚本效率不高

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13228630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:42:17  来源:igfitidea点击:

shell script for Net-snmp (get/walk) is not efficient

bashshellsnmpnet-snmp

提问by Jatin Bodarya

#!/bin/bash
for i in `seq 1 3000`
do
    index=`snmpget -v 2c -c public -Oqv localhost 1.3.6.1.4.1.21067.4.1.1.1.$i` 
done

for i in `seq 1 3000`
do
    upload=`snmpget -v 2c -c public -Oqv localhost 1.3.6.1.4.1.21067.4.1.1.10.$i` 
done

for i in `seq 1 3000`
do
    download=`snmpget -v 2c -c public -Oqv localhost 1.3.6.1.4.1.21067.4.1.1.11.$i` 
done

(ubuntu-12.04) above is my shell script....with every execution of snmpget command it returns an integer and stores value in above three variables... the problem is the data table is of 9000 values. so with this script it is giving too much time consuption and bettelnake.

(ubuntu-12.04) 上面是我的 shell 脚本....每次执行 snmpget 命令时,它都会返回一个整数并将值存储在上述三个变量中...问题是数据表有 9000 个值。所以这个脚本给了太多的时间消耗和bettelnake。

can any one suggest me some simple "SNMPWALK"(or anything else) used script with that I can store all this data in to a single array[9000] or with three parse,in three different arrays with index of 1 to 3000.so I can decrease time as much as possible.

任何人都可以建议我一些简单的“SNMPWALK”(或其他任何东西)使用的脚本,我可以将所有这些数据存储到一个数组[9000]或三个解析中,在三个不同的数组中,索引为1到3000.so我可以尽量减少时间。

for example : snmpwalk -v 2c -c public -Oqv localhost 1.3.6.1.4.1.21067 gives all the values,but I dont know how to store all these in a array with different index. ..................................................................

例如: snmpwalk -v 2c -c public -Oqv localhost 1.3.6.1.4.1.21067 给出了所有值,但我不知道如何将所有这些值存储在具有不同索引的数组中。………………………………………………………………………………………………………………………………………………………… …………………………………………………………………………………………………………………………………………

see I have tried below : but giving me errors...

看到我在下面尝试过:但是给了我错误...

cat script.sh

 #!/bin/sh
OUTPUT1=$(snmpbulkwalk -Oqv -c public -v 2c localhost 1.3.6.1.2.1.2.2.1.1 2> /dev/null)
i=1
for LINE in ${OUTPUT1} ;
    do
        OUTPUT1[$i]=$LINE;
        i=`expr $i + 1`
    done

sh script.sh
j4.sh: 6: j4.sh: OUTPUT1[1]=1: not found
j4.sh: 6: j4.sh: OUTPUT1[2]=2: not found

回答by uml?ute

try something like this:

尝试这样的事情:

OID="1.3.6.1.4.1.21067.4.1.1"

declare -a index=($(snmpwalk-v 2c -c public -Oqv localhost ${OID}.1))
declare -a upload=($(snmpwalk-v 2c -c public -Oqv localhost ${OID}.10))
declare -a download=($(snmpwalk-v 2c -c public -Oqv localhost ${OID}.11))

echo "retrieved ${#index[@]} elements"
echo"#${index[1]}: up=${upload[1]} down=${download[1]}

note, that in general i would suggest to use some higher-level language (like python) rather than bashto work more efficiently with snmp...

请注意,通常我会建议使用一些高级语言(如python)而不是bash来更有效地使用 snmp ...

回答by user2908294

I would suggest if its a table that you are retrieving use SNMPTABLE rather than walk or get.

如果它是您要检索的表,我建议您使用 SNMPTABLE 而不是 walk 或 get。