Operating System - HP-UX
1753937 Members
10067 Online
108811 Solutions
New Discussion юеВ

Re: best practice to check VG state

 
SOLVED
Go to solution
Viktor Balogh
Honored Contributor

best practice to check VG state

Hi everybody,

What is the best practice to check the state of a volume group? I mean to check in what state it is in? (exclusive/active rw/active ro/inactive)

I need this for an automated script. Until now I did a vgdisplay to that VG and looked for the exit status. Is there any specific command to do this?

Regards,
Viktor
****
Unix operates with beer.
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: best practice to check VG state

Hi Viktor:

Depending upon your objective, I'd do:

# vgdisplay -v vg_name

(or on 11.31)

# vgdisplay -vF vg_name

...and parse out the fields you want to examine.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: best practice to check VG state

Shalom Viktor,

I would in addition to vgdisplay options recommend this:

vgcfgbackup

It there is a problem, it will fail with a non-zero error code.

Great way to find trouble before it gets out of control.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Viktor Balogh
Honored Contributor

Re: best practice to check VG state

thank you for the responses so far.

>...and parse out the fields you want to examine.

Yepp, but what if the vg isn't activated? I want to have a solution also in case it is disabled. Any better method than checking the output of vgdisplay?

****
Unix operates with beer.
James R. Ferguson
Acclaimed Contributor

Re: best practice to check VG state

Hi (again) Viktor:

Yepp, but what if the vg isn't activated?

Then you would not have any (STDOUT) output. The absence of which would be an indication that the state wasn't what you wanted.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: best practice to check VG state

If a VG is not activated, then you will get this:

# vgdisplay vg03
vgdisplay: Volume group not activated.
vgdisplay: Cannot display volume group "vg03".

You wold have to make allowances for this in your script. If a VG is not activated you are not going to be able to get much information from it.
Patrick Wallek
Honored Contributor

Re: best practice to check VG state

Here's a quick script I came up with to check the status of VGs on a system. It assumes all VGs begin with 'vg' as the first 2 characters in their name.

#!/usr/bin/sh
for VG in $(ls ├в 1d /dev/vg*)
do
vgdisplay ${VG} 2>&1 | grep ├в q "not activated"
VGRETCD=$?
if [[ "${VGRETCD}" ├в eq 0 ]] ; then
echo "${VG} is not active. No further information is available"
echo ""
else
echo "${VG} Information:"
vgdisplay ${VG} |grep ├в e Access ├в e Status
echo ""
fi
done
Patrick Wallek
Honored Contributor
Solution

Re: best practice to check VG state

Damn Windows cut-and-paste!!!!

Here's the correct script without the garbage characters.

#!/usr/bin/sh
for VG in $(ls -1d /dev/vg*)
do
vgdisplay ${VG} 2>&1 | grep -q "not activated"
VGRETCD=$?
if [[ "${VGRETCD}" -eq 0 ]] ; then
echo "${VG} is not active. No further information is available"
echo ""
else
echo "${VG} Information:"
vgdisplay ${VG} |grep -e Access -e Status
echo ""
fi
done

Here's output from the script:
# sh ./test1.sh
/dev/vg00 Information:
VG Write Access read/write
VG Status available

/dev/vg02 is not active. No further information is available

/dev/vg03 is not active. No further information is available

/dev/vg04 Information:
VG Write Access read/write
VG Status available, exclusive

/dev/vg05 Information:
VG Write Access read/write
VG Status available
Viktor Balogh
Honored Contributor

Re: best practice to check VG state

Ok, so the only way to check if a vg is activated is with the vgdisplay command. That's what I wanted to know. Thank you for all the responses.
****
Unix operates with beer.