1834135 Members
2240 Online
110064 Solutions
New Discussion

capture command output

 
SOLVED
Go to solution
Rick Garland
Honored Contributor

capture command output

Hi all:

Trying to capture the output of the cammand vgdisplay.

I am in a SG environment so not all VGs are active .
What I am doing
vgdisplay | awk '$0~"VG Name"{print substr($NF,6)}'

The VGs that are not active are echoing to screen. I cannot get them into $LOG file.

I have done 2>&1 but no luck.

Any ideas?
12 REPLIES 12
Alan Meyer_4
Respected Contributor

Re: capture command output

How about this?

ls /dev/*/group |cut -f3 -d"/"
" I may not be certified, but I am certifiable... "
Sandman!
Honored Contributor

Re: capture command output

Rick,

Have you tried command grouping? I run a variation of your command on a regular basis and it works fine for me.

# { vgdisplay | awk '$0~"VG Name"'; } > out_file 2>&1

OR

# ( vgdisplay | awk '$0~"VG Name"' ) > out_file 2>&1


cheers!
Sandman!
Honored Contributor

Re: capture command output

Rick,

I tried your command on my HP system and the only way I could get it to work was by command grouping and piping the output of your command into another awk construct. I'ave pasted the command that I ran on my system and it might be what you're looking for.


# { vgdisplay | awk '$0~"VG Name"' | awk -F"VG Name *" '{print $2}'; } > outfile 2>&1

OR

# ( vgdisplay | awk '$0~"VG Name"' | awk -F"VG Name *" '{print $2}' ) > outfile 2>&1


cheers!

Alan Meyer_4
Respected Contributor

Re: capture command output

how about this?

vgdisplay 2>&1 |grep '/dev/' |cut -f3 -d'/' |cut -f1 -d'"'
" I may not be certified, but I am certifiable... "
generic_1
Respected Contributor

Re: capture command output

script -a :)
Rick Garland
Honored Contributor

Re: capture command output

Hi folks:

Tried the responses but what is getting to the $LOG file are the VGs that are active. And this is good.

What I see is the following:

vgdisplay: Volume group not activated.
vgdisplay: Cannot display volume group "/dev/vg1".
vgdisplay: Volume group not activated.
vgdisplay: Cannot display volume group "/dev/vg2".

I have tried pipes, script, the /dev/group entries, etc.

Those VGs that are cluster aware and are not presently active on a node, I cannot get into $LOG.

In my script, here is the line I am doing
VG_LIST=`vgdisplay | awk '$0~"VG Name"{print substr($NF,6)}'`

I have tried >/dev/null 2>&1 >> $LOG, piping through the 'tee' command, using the script function, etc...
No working.


Alan Meyer_4
Respected Contributor
Solution

Re: capture command output

Rick, the problem is that you are searching for the string "VG Name", on the inactive VG's that string does not appear.

when I use your command I get this:

[root@pyrite] > VG_NAME=`vgdisplay | awk '$0~"VG Name"{print substr($NF,6)}'`
vgdisplay: Volume group not activated.
vgdisplay: Cannot display volume group "/dev/vgqdx".
[root@pyrite] > echo $VG_NAME
vg00 vg09 vg07 vg02 vg01 vg03 vg04 vg06 vg05
[root@pyrite] >

by changing it to search for the string "/dev/" I get this:

[root@pyrite] > VG_NAME=`vgdisplay 2>&1 |grep '/dev/' |cut -f3 -d'/' |cut -f1 -d'"'
[root@pyrite] > echo $VG_NAME
vgqdx vg00 vg09 vg07 vg02 vg01 vg03 vg04 vg06 vg05
[root@pyrite] >

" I may not be certified, but I am certifiable... "
Rick Garland
Honored Contributor

Re: capture command output

Alan:

I do need the "Volume Groupo not active" messages in the $LOG file as well.

Mel Burslan
Honored Contributor

Re: capture command output

Rick,

I can not find a way to do it in one command but these two will do the trick:

vgdisplay 2>/tmp/err | grep "VG Name" | awk {'print $3'} |cut -d/ -f3 > /tmp/out
grep Cannot /tmp/err|cut -d/ -f3|cut -d\" -f1>>/tmp/out

hope this helps
________________________________
UNIX because I majored in cryptology...
Alan Meyer_4
Respected Contributor

Re: capture command output

can they be seperate entries like:

ACT_VGs=`vgdisplay 2>&1 | awk '$0~"VG Name"{print substr($NF,6)}'`
INACT_VGs=`vgdisplay 2>&1 |grep '^vgdisplay:'
" I may not be certified, but I am certifiable... "
Rick Garland
Honored Contributor

Re: capture command output

DING DING DING

Mel and Alan. Got it.

Put the error handling before my pipes.

Many thanks to all.




Rick Garland
Honored Contributor

Re: capture command output

The solution.

VG_LIST=`vgdisplay 2>>$LOG | awk '$0~"VG Name"{print substr($NF,6)}'`

Works like a champ. I get the inactive clustered VGs as well as the active ones in the $LOG file.