msgbartop
Tips and Tricks site for advanced HP-UX Engineers
msgbarbottom

16 Dec 21 Linux vgs port for HPUX (updated to work with vg version 2.2)

A while back, I came across a port of the very nice linux vgs command for HP-UX. A h/t to Juan Manuel Rey (juanmanuel.reyportal@gmail.com) for that original version.

But, upon using it recently, I noted it was not working now that we have some volume groups with vg version 2.2. Here is a modified version of the script that works for version 2.2 volume groups!

#!/sbin/sh
#
# vgs.sh - script to emulate the Linux LVM command vgs in HP-UX 11iv3
#
# (C) 2010 - Juan Manuel Rey (juanmanuel.reyportal@gmail.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

version="v0.2 2021/12/15"

usage() {
  echo
  echo "VGS for HP-UX ${version}"
  echo
  echo "Usage: vgs [-v vg_name]"
  echo
  exit 1
}

if [ ! "$(uname -r)" = "B.11.31" ]; then
   echo "VGS for HP-UX only works on HP-UX 11iv3"
   exit 1
fi

if [ "$1" ]; then
"vgs" 87 lines, 3053 characters

if [ "$1" ]; then
   case "$1" in
   -v) shift; [  "$1" = "" ] && usage || vg_name=${1};;
   *)  usage;;
   esac
fi

vg_display="vgdisplay -F"
[ ! "${vg_name}" = "" ] && vg_display="vgdisplay -F ${vg_name}"

printf "%-10s %-5s %-5s %-20s %-8s %-6s %-5s\n" VG PVs LVs Status Version VGSize Free

# First, we must determine which VG Version we have

eval ${vg_display} | \
  while IFS=":" read vgdisplay; do
     version=$(echo ${vgdisplay} | awk -F: '{for (i=1;i<=NF;i++) print $i}' | grep vg_version | cut -d= -f2)
     case "$version" in
       2.2) total_pe_index=15
            pe_size_index=13
            free_pe_index=18
            cur_pv_index=9
            ;;
         *) total_pe_index=13
            pe_size_index=12
            free_pe_index=15
            cur_pv_index=8
            ;;
     esac

     echo ${vgdisplay} | cut -d ":" -f 2 | cut -d "=" -f 2 | read status
     if [ "${status}" = "deactivated" ]; then
        status=deactivated
        vg_size=""
        vg_free=""
     else
        echo ${vgdisplay} | cut -d ":" -f 3  | cut -d "=" -f 2 | read status
     else
        echo ${vgdisplay} | cut -d ":" -f 3  | cut -d "=" -f 2 | read status
        echo ${vgdisplay} | cut -d ":" -f ${total_pe_index} | cut -d "=" -f 2 | read total_pe
        echo ${vgdisplay} | cut -d ":" -f ${pe_size_index} | cut -d "=" -f 2 | read pe_size
        echo ${vgdisplay} | cut -d ":" -f ${free_pe_index} | cut -d "=" -f 2 | read free_pe
        vg_size="`/usr/bin/expr $total_pe \* $pe_size / 1024`G"
        vg_free="`/usr/bin/expr $free_pe \* $pe_size / 1024`G"
     fi

     echo ${vgdisplay} | cut -d ":" -f 1 | cut -d "=" -f 2 | cut -d "/" -f 3 | read vg_name
     echo ${vgdisplay} | cut -d ":" -f ${cur_pv_index} | cut -d "=" -f 2 | read pvs
     echo ${vgdisplay} | cut -d ":" -f 5 | cut -d "=" -f 2 | read lvs
     #echo ${vgdisplay} | cut -d ":" -f 19 | cut -d "=" -f 2 | read version
     printf "%-10s %-5s %-5s %-20s %-8s %-6s %-5s\n" "${vg_name}" "${pvs}" "${lvs}" "${status}" "${version}" "${vg_size}" "${vg_free}"
done

Tags:

WhatsApp chat