1833742 Members
2499 Online
110063 Solutions
New Discussion

Format "cmviewcl" output

 
SOLVED
Go to solution
Faisal Qureshi
Advisor

Format "cmviewcl" output

Can I format "cmviewcl" output like following?

PACKAGE STATUS STATE PKG_SWITCH CURRENT_NODE PRIMARY_NODE

10 REPLIES 10
Justo Exposito
Esteemed Contributor

Re: Format "cmviewcl" output

Hi,

Perhaps something like this?
cmviewcl | sort -u |sed '/^$/d' |head -4

if you have 3 pakages then head -4
2 packages -> head -3
1 packages -> head -2

Hope this help,

Justo.
Help is a Beatiful word
Faisal Qureshi
Advisor

Re: Format "cmviewcl" output

No that did not help.
I would like to display 6 columns like follows:

1st column: PACKAGE
2nd column: STATUS
3rd column: STATE
4th column: PKG_SWITCH
5th column: CURRENT NODE
6th column: PRIMARY NODE

I can display first 5 columns with the following command:

cmviewcl -l package | grep -v PACK

What I want is to display the 6th column.
Thanks.
Justo Exposito
Esteemed Contributor
Solution

Re: Format "cmviewcl" output

Hi Again,
Something like this?

echo "PACKAGE STATUS STATE PKG_SWITCH NODE Primary"
for i in `cmviewcl | sort -u |sed '/^$/d' |head -4 | tail -3| sed 's/\ \{1,\}/#/g'`
do
PKG=`echo $i | cut -d"#" -f2`
PRI=`cmviewcl -v -p $PKG | grep "Primary"|sed 's/\ \{1,\}/#/g' | cut -d"#" -f5`
echo "$i#$PRI" |sed 's/#/ /g'
done

Regards,

Justo.
Help is a Beatiful word
Justo Exposito
Esteemed Contributor

Re: Format "cmviewcl" output

Hi,

This is the script.

Regards,

Justo.
Help is a Beatiful word
John Palmer
Honored Contributor

Re: Format "cmviewcl" output

Try this simple script...

#!/usr/bin/sh
#
cmviewcl -l package | grep -v PACK | {
while read PACKAGE STATUS STATE SWITCH CURRNODE
do
if [[ -z ${PACKAGE} ]];
then continue
fi

PRIMARY=$(cmviewcl -v -l package -p ${PACKAGE} | grep " Primary" | awk '{print
$4}')
printf "%12s %12s %12s %12s %12s %12s\n" ${PACKAGE} ${STATUS} ${STATE} ${SWITCH
} ${CURRNODE} ${PRIMARY}
done
}

Regards,
John
Faisal Qureshi
Advisor

Re: Format "cmviewcl" output

Is it possible to do just one 'cmviewcl' command and then do all the parsing? I have 20 packages and it takes 14 seconds to run.
John Palmer
Honored Contributor

Re: Format "cmviewcl" output

Try this as a basis:-

#!/usr/bin/sh
#
cmviewcl -l package -v|grep -e "^ [^ ]" -e "(current)" | {
while read PACKAGE STATUS STATE SWITCH CURRNODE
do
if [[ -z ${PACKAGE} || ${STATUS} = STATUS ]];
then continue
fi

read A B C PRIMARY E || exit

printf "%12s %12s %12s %12s %12s %12s\n" ${PACKAGE} ${STATUS} ${STATE} ${SWITCH
} ${CURRNODE} ${PRIMARY}
done
}


Regards,
John
Justo Exposito
Esteemed Contributor

Re: Format "cmviewcl" output

Hi Faisal,

You can try to extract the information from the /etc/cmcluster/pakagename/pakagename.conf file, in order to do this you can try this:
PRI=`grep "^NODE_NAME" /etc/cmcluster/$PKG/$PKG.conf | head -1 | sed 's/\ \{1,\}/#/g' | cut -d"#" -f2`

Regards,

Justo.
Help is a Beatiful word
Faisal Qureshi
Advisor

Re: Format "cmviewcl" output

I'm trying to get the following output with one "cmviewcl" command:
PKG STATUS STATE PKG_SWTCH CURRENT_NODE PRIMARY_NODE
DB1 up running enabled server1 server1
DB2 up running enabled server1 server2
DB3 up running enabled server2 server1
.
.
.

Thanks.
Geoff Wild
Honored Contributor

Re: Format "cmviewcl" output

I would send it to a file:

FILE-/tmp/cmviewcl.log
cmviewcl > $FILE

if [ ! $? ] || grep -v unowned $FILE | egrep -q ' down| failed'; then
COLOR="red"
elif grep -v unowned $FILE | egrep -q ' unknown| initializing| reforming| halted'; then
COLOR="yellow"
else
COLOR="green"
fi

Once it is in a file, then you can format the data any way you want...plus, you can go back and verify the contents...


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.