1.11M Members

Configuration file query

 
0
 

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

 
0
 

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.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: