We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,453 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Configuration file query

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

1
Contributor
1
Reply
1 Day
Discussion Span
2 Years Ago
Last Updated
2
Views
cshanek
Newbie Poster
2 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

cshanek
Newbie Poster
2 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0676 seconds using 2.64MB