Note that there are some explanatory texts on larger screens.

plurals
  1. POshell script : array related issue
    text
    copied!<p>using linux 2.6.18.. </p> <pre><code>/bin/bash -version GNU bash, version 1.14.7(1) </code></pre> <p>(snmpwalk command gives output in a console like...below)</p> <pre><code>33 4232 5342 632 45342 23342 3243 </code></pre> <p>I am using shell script to grep data from snmp and trying to add it in array. but cannot do this with following problems...</p> <pre><code>#!/bin/bash OID="1.3.6.1.2.1.2.2.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[3]}: up=${upload[2]} down=${download[2]}" </code></pre> <p>output:</p> <pre><code> + declare -a index=1 2 j2.sh: 4: j2.sh: declare: not found </code></pre> <p>(so I can not use 'declare')</p> <p>2nd way </p> <pre><code>#!/bin/bash OUTPUT1=$(snmpbulkwalk -Oqv -c public -v 2c localhost 1.3.6.1.4.1.21067.4.1.1.1 2&gt; /dev/null) i=1 index=1 upload=1 download=1 for LINE in ${OUTPUT1} do index=$LINE OUTPUT2=$(snmpget -Oqv -c public -v 2c localhost 1.3.6.1.4.1.21067.4.1.1.10.$i 2&gt; /dev/null) OUTPUT3=$(snmpget -Oqv -c public -v 2c localhost 1.3.6.1.4.1.21067.4.1.1.11.$i 2&gt; /dev/null) upload=$OUTPUT2 download=$OUTPUT3 i=`expr $i + 1` done </code></pre> <p>its gives bettelnack with large amount of data...</p> <p>3ra approch :</p> <pre><code>#!/bin/bash OUTPUT=$(snmpbulkwalk -Oqv -c public -v 2c localhost 1.3.6.1.4.1.21067.4.1.1.1 2&gt; /dev/null) i=0 index[3000]=0 for LINE in ${OUTPUT} ; do index[$i]=$LINE i=`expr $i + 1` done </code></pre> <p>here index[1],index[2]...... are not fount</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload