I have a configuration file (listen.conf) with the following format:

[jupiter]
event_class="jupiter_bypass"
event_state="active"

[hammer]
event_class="halt_snmp"
event_state="active"

[thor]
even_class="meh"
event_state=inactive

...

What would be the best way to return event_class names of all inactive and/or active events (event_state's)?

Thanks in advance,
Shane

Well here is what I came up with:

show_applications()
{
    declare -a ACT_ARRAY
        declare -a INACT_ARRAY
        echo "CSListener Application Event Information:"
        echo ""
        echo "ACTIVE EVENTS:"
        echo "======================"
        ACT_ARRAY=`awk -F"=" '/^event_class/{ x=$2; } /^event_state/ { if ($2 !~ /inactive/) {print x;}}' /etc/csevents.conf` 
        for event in ${ACT_ARRAY[@]}; do
            echo $event | sed "s/^\([\"']\)\(.*\)\1\$/\2/g"
        done
        echo ""
        echo "INACTIVE EVENTS:"
        echo "======================"
        INACT_ARRAY=`awk -F"=" '/^event_class/{ y=$2; } /^event_state/ { if ($2 = /inactive/) {print y;}}' /etc/csevents.conf` 
        for event in ${INACT_ARRAY[@]}; do
            echo $event | sed "s/^\([\"']\)\(.*\)\1\$/\2/g" 
        done
        echo ""        
}

I am sure I could tweak a couple of things to make it better + more elegant.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.