2

This script was working just fine on an AIX box, but now on RH linux box the arrays just doesn't seem to work. Version on the new RH box is 4.1.2

I declare my array

declare -a gridNames=()

I get information about a grid

gridstats=`snmpwalk -v 2c -c splunk $host gridStatsTable -m $APPLIANCEMIB -OUQs -Ln`

As well as getting the stats from the above, I reuse it to find all the gridNames and then will use the array of gridNames to get stats about their maps.

while read -r process; do
        gridNames=(${gridNames[@]} `grep gridName | awk -F "\"" '{print $(NF-1)}'`)
done <<< "$gridstats"

The awk part is tested and correctly returns a list of gridnames (just one in this case) but when I echo the array gridNames its empty.

I have also tried using

gridNames+=(`grep gridName | awk -F "\"" '{print $(NF-1)}'`)

but that doesnt work either

1 Answer 1

2

You need to use += operator for appending elements to an array with process substitution:

while read -r process; do
    gridNames+=( $(grep 'gridName' | awk -F '"' '{print $(NF-1)}' <<< "$process") )
done < <(snmpwalk -v 2c -c splunk $host gridStatsTable -m $APPLIANCEMIB -OUQs -Ln)
Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm yup while read -r process; do gridNames+=( $(grep 'gridName' | awk -F '"' '{print $(NF-1)}' <<< "$process") ) done <<< "$gridstats" seems to work. I cant pretend for one moment to understand it though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.