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
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
© 2013 DaniWeb® LLC
Page rendered in 0.0676 seconds
using 2.64MB