Agnus Dei (jackal) wrote,
Agnus Dei
jackal

Using associative arrays in bash (Example)

Example of using associative arrays in bash.

declare -A ELB_REGION=(
        ["AAAA-ELB"]="us-east-1"
        ["BBBB-ELB"]="us-west-1"
        ["CCCC-ELB"]="us-east-1"
)
declare -A ELB_CRITIALLIMIT=(
        ["AAAA-ELB"]="-1"
        ["BBBB-ELB"]="0"
        ["CCCC-ELB"]="0"
)

# Test for each ELB
for ELB in "${!ELB_REGION[@]}"
do
        # echo $ELB ${ELB_REGION[$ELB]} ${ELB_CRITIALLIMIT[$ELB]}
        RESULTS=`/usr/local/bin/check_elb_health.sh -r  ${ELB_REGION[$ELB]} -c ${ELB_CRITIALLIMIT[$ELB]}  $ELB`
        RETURNCODE=$?
        # RETURNCODE=2  # set for debugging
        track_worst_result $RETURNCODE  # External function

        # Capture the results for any bad checks
        if [[ "$RETURNCODE" -gt "0" ]]; then
                FINALRESULTS="$RESULTS $FINALRESULTS"
        fi
done
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 0 comments