<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: adding elements to an array in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990844#M100392</link>
    <description>Done</description>
    <pubDate>Fri, 14 Jul 2006 11:46:46 GMT</pubDate>
    <dc:creator>Chris Vidal</dc:creator>
    <dc:date>2006-07-14T11:46:46Z</dc:date>
    <item>
      <title>adding elements to an array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990840#M100388</link>
      <description>snmpwalk -c xx yy system  generates the following. &lt;BR /&gt;&lt;BR /&gt;cvidal@cayd04-mds1:~&amp;gt; snmpwalk -c tmedomain4 192.168.63.247 system&lt;BR /&gt;sysDescr.0 = STRING: Cisco IOS Software, 3800 Software (C3845-ADVIPSERVICESK9-M), Version 12.4(3b), RELEASE SOFTWARE (fc3)&lt;BR /&gt;Technical Support: &lt;A href="http://www.cisco.com/techsupport" target="_blank"&gt;http://www.cisco.com/techsupport&lt;/A&gt;&lt;BR /&gt;Copyright (c) 1986-2005 by Cisco Systems, Inc.&lt;BR /&gt;Compiled Fri 09-Dec-05 09:08 by alnguyen&lt;BR /&gt;sysObjectID.0 = OID: enterprises.9.1.544&lt;BR /&gt;sysUpTime.0 = Timeticks: (28557767) 3 days, 7:19:37.67&lt;BR /&gt;sysContact.0 = STRING: MCI 800-256-9284&lt;BR /&gt;sysName.0 = STRING: merv-m008napa-687103&lt;BR /&gt;sysLocation.0 = STRING:&lt;BR /&gt;sysServices.0 = INTEGER: 78&lt;BR /&gt;sysORLastChange.0 = Timeticks: (0) 0:00:00.00&lt;BR /&gt;&lt;BR /&gt;I would like to put each line into an array element as I receive the response for later printing or assigning to vars &lt;BR /&gt;&lt;BR /&gt;set -A ARRAY just setsup  a single element array. &lt;BR /&gt;&lt;BR /&gt;tks</description>
      <pubDate>Thu, 13 Jul 2006 16:55:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990840#M100388</guid>
      <dc:creator>Chris Vidal</dc:creator>
      <dc:date>2006-07-13T16:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: adding elements to an array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990841#M100389</link>
      <description>&amp;gt;I would like to put each line into an array element as I receive the response for &amp;gt;later printing or assigning to vars&lt;BR /&gt;&lt;BR /&gt;# snmpwalk -c xx yy system | awk '{l[NR]=$0}'</description>
      <pubDate>Thu, 13 Jul 2006 17:19:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990841#M100389</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-07-13T17:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: adding elements to an array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990842#M100390</link>
      <description>Here's a simple example using the output of ls -l /tmp but it should give you the idea:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset PROG=${0}&lt;BR /&gt;typeset -i MAXARRAY=1023&lt;BR /&gt;typeset -i KNT=0&lt;BR /&gt;typeset X=""&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;&lt;BR /&gt;#your snmpwalk will replace the ls -l&lt;BR /&gt;&lt;BR /&gt;ls -l /tmp | while read X&lt;BR /&gt;  do&lt;BR /&gt;    typeset A[${KNT}]="${X}"&lt;BR /&gt;    ((KNT += 1))&lt;BR /&gt;    if [[ ${KNT} -gt ${MAXARRAY} ]]&lt;BR /&gt;      then&lt;BR /&gt;        STAT=255&lt;BR /&gt;        echo "${PROG}: Missing elements" &amp;gt;&amp;amp;2&lt;BR /&gt;        break&lt;BR /&gt;      fi&lt;BR /&gt;  done&lt;BR /&gt;# Now let's read 'em out&lt;BR /&gt;typeset -i I=0&lt;BR /&gt;while [[ ${I} -lt ${KNT} ]]&lt;BR /&gt;  do&lt;BR /&gt;    echo "${I} -&amp;gt; \"${A[${I}]}\""&lt;BR /&gt;    ((I += 1))&lt;BR /&gt;  done&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;----------------------------&lt;BR /&gt;&lt;BR /&gt;Note that shell arrays are limited to a maximum of 1024 elements so you might want to rethink your problem (Perl?).&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jul 2006 17:30:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990842#M100390</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-07-13T17:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: adding elements to an array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990843#M100391</link>
      <description>&lt;!--!*#--&gt;You could maybe try something like&lt;BR /&gt; &lt;BR /&gt;typeset -i i=-1; set -A SNMPWALK&lt;BR /&gt;/your/snmpwalk_cmd 2&amp;gt;/dev/null \&lt;BR /&gt;| while read line; do&lt;BR /&gt;    SNMPWALK[$((i+=1))]="$line"&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;But beware not to start your snmpwalk too high in the tree because afaik a shell array can only hold up to 1024 elements.&lt;BR /&gt;Besides, because of wasteful memory usage&lt;BR /&gt;dumping large amounts of output in arrays is not considered terribly efficient programming.&lt;BR /&gt; &lt;BR /&gt;In Perl it is much easier to store each output line as an array element,&lt;BR /&gt;and there you are only restricted by your process'es memory share.&lt;BR /&gt;But for efficiency's sake one shouldn't store it in an array.&lt;BR /&gt; &lt;BR /&gt;e.g.&lt;BR /&gt; &lt;BR /&gt;my @SNMPWALK = qx(/your/snmpwalk_cmd);&lt;BR /&gt;&lt;BR /&gt;or if you want more control&lt;BR /&gt;&lt;BR /&gt;local *SNMP_PIPE&lt;BR /&gt;my $child = open SNMP_PIPE, '-|';&lt;BR /&gt;die "Cannot open pipe to snmpwalk" if !defined $child;&lt;BR /&gt;if ($child) {&lt;BR /&gt;    @SNMPWALK = &lt;SNMP_PIPE&gt;;&lt;BR /&gt;    close SNMP_PIPE;&lt;BR /&gt;} else {&lt;BR /&gt;    local %ENV; # if taint mode demands&lt;BR /&gt;    exec qw(/path/to/snmpwalk arg1 arg2 arg3);&lt;BR /&gt;}&lt;BR /&gt;# maybe you want to chomp new lines&lt;BR /&gt;chomp @SNMPWALK&lt;BR /&gt;&lt;/SNMP_PIPE&gt;</description>
      <pubDate>Fri, 14 Jul 2006 02:18:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990843#M100391</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2006-07-14T02:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: adding elements to an array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990844#M100392</link>
      <description>Done</description>
      <pubDate>Fri, 14 Jul 2006 11:46:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/adding-elements-to-an-array/m-p/4990844#M100392</guid>
      <dc:creator>Chris Vidal</dc:creator>
      <dc:date>2006-07-14T11:46:46Z</dc:date>
    </item>
  </channel>
</rss>

