Friday, 11 July 2008

get_vgids

This script will get the VGID for the named volume group and it's PDs

#!/usr/bin/ksh

# find all the disks presented to the system that have the VGID of the named
# volume groups.
# This is helpful when you present the BCVs for a devicegroup that has
# a number of volume groups on it.

[[ $# -lt 1 ]] && echo "[FATAL]Must give one or more volume groups" && exit 1
[[ $(uname -s) != 'HP-UX' ]] && echo "[FATAL]Only works on Solaris" && exit 1

# get VGIDs from lvmtab
typeset _volume_groups="$@"
typeset _volume_group
typeset _offset
typeset _vg_path
typeset _vgid
typeset _vgid1
typeset _vgid2
typeset _disk
typeset _disk_vgid

# find the VGID of the volumes.
for _volume_group in $_volume_groups
do
_volume_group=$(basename $_volume_group)
strings -t d /etc/lvmtab | grep $_volume_group | read _offset _vg_path
if [[ -n "$_offset" && -n "$_vg_path" ]]; then
xd -An -j$(($_offset+1024)) -N8 -tuL /etc/lvmtab | grep -vE '^$'| read _vgid1 _vgid2
_vgid="${_vgid1}-${_vgid2}"
print $_vg_path $_vgid
# get VGIDs from PV
for _disk in /dev/rdsk/*
do
_size=$(diskinfo -b $_disk 2> /dev/null)
if [[ $_size -gt 0 ]]; then
_disk_vgid=$(xd -An -j8208 -N8 -tuL $_disk | awk '/[0-9]/ {print $1 "-" $2}')
if [[ "$_disk_vgid" = "$_vgid" ]]; then
print $_vg_path $_disk $_disk_vgid
fi
fi
done
else
print "[FATAL]Can't find $_volume_group in /etc/lvmtab"
fi
done

No comments: