0
#!/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.

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.

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. ..................................................................

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
Jatin Bodarya
  • 1,425
  • 2
  • 20
  • 32

2 Answers2

0

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 bash to work more efficiently with snmp...

umläute
  • 28,885
  • 9
  • 68
  • 122
  • actually I am very much new in scripts.. It is showing me syntex error "(" unexpected on 3rd line . see these are my vendor specific mibs... just like ifindex,ifInoctets,ifOutoctects – Jatin Bodarya Nov 06 '12 at 09:00
  • I see that you are using SNMPv2c already. Try to use snmpbulkwalk or snmpbulkget to speedup data retrieval process. Here is the snmpbulkwalk man page. Please note that you can configure this command using especially -Cr and -Cn options. The snmpbulkwalk minimize network traffic by avoiding a huge amount of small PDUs and moreover it limits number of PDU' pack/unpack calls. – lucassm Nov 06 '12 at 09:01
  • it seems that you have the stderr-redirection split in two lines (make sure that 2>/dev/null is in the same line #2) – umläute Nov 06 '12 at 10:44
  • are you sure you are running `bash`? try changing the shebang from `#!/bin/sh` to `#!/bin/bash` – umläute Nov 08 '12 at 08:45
  • I am using bash.. but the problem is the bash version is 1.4 and it does not support array. – Jatin Bodarya Nov 09 '12 at 05:25
  • oh, current bash is 4.2...bash-1.14 was released somewhen in 1996; are you sure that you are using 1.4? – umläute Nov 09 '12 at 10:48
0

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