1754985 Members
2723 Online
108828 Solutions
New Discussion юеВ

VG Info script

 
SOLVED
Go to solution
Dewa Negara_4
Regular Advisor

VG Info script

Hi All,

Could you please help? I want to create a script to collect all VGs information from the system. The output of the script should ...

What command should I use in thes script?

Please help.

Thanks and Best Regards,
Dewa
Santos
6 REPLIES 6
Ivan Krastev
Honored Contributor

Re: VG Info script

To collect basic info - name, PE size, free PE .. use:


vgdisplay | grep -E "VG Name|PE Size|Total PE|Alloc PE|Free PE"

after that you can calculate the size in MB for Total/Alloc/Free based on PE size.


regards,
ivan
rariasn
Honored Contributor
Solution

Re: VG Info script

Hi Dewa:

TOTAL=0
echo
for VG in $(ls -d /dev/vg*)
do
vgdisplay -v $VG > /dev/null 2>&1
if [ $? -eq 0 ]
then
PESIZE=$(vgdisplay $VG|grep "PE Size"|awk '{print $4}')
FREEPE=$(vgdisplay $VG|grep "Free PE"|awk '{print $3}')
let ESPACIO=$PESIZE*$FREEPE
typeset -12R ESPACIO
typeset -30L VG
echo "---$VG:$ESPACIO"
let TOTAL=$TOTAL+ESPACIO
fi
done
typeset -14R TOTAL

echo "==============================================="
echo "+++TOTAL:\t\t\t$TOTAL"
echo "==============================================="
echoTOTAL=0
echo
for VG in $(ls -d /dev/vg*)
do
vgdisplay -v $VG > /dev/null 2>&1
if [ $? -eq 0 ]
then
PESIZE=$(vgdisplay $VG|grep "PE Size"|awk '{print $4}')
FREEPE=$(vgdisplay $VG|grep "Free PE"|awk '{print $3}')
let ESPACIO=$PESIZE*$FREEPE
typeset -12R ESPACIO
typeset -30L VG
echo "---$VG:$ESPACIO"
let TOTAL=$TOTAL+ESPACIO
fi
done
typeset -14R TOTAL

echo "==============================================="
echo "+++TOTAL:\t\t\t$TOTAL"
echo "==============================================="
echo

Output:

fonseca:/Administracion/Discos/script#./espacio_vgs.sh

---/dev/vg00 : 29616
---/dev/vg01 : 25396
---/dev/vgbatch.desa : 1356
---/dev/vgoracle.desa : 2512
===============================================
+++TOTAL: 58880
===============================================

rgs,
Dewa Negara_4
Regular Advisor

Re: VG Info script

Thanks alot Ivan & Rariasn. It looks fine to me now.

Thanks again.
Santos
Alzhy
Honored Contributor

Re: VG Info script

Dewa,

Save this as /usr/local/bin/vginfo and change to executable (edit location of perl). I got this script from ITRC and made some minor mods to it:

#!/usr/contrib/bin/perl
#
# vginfo - display comprehensive information on LVM COnfiguration
# incluiding VG's, LV's and PVs
#
#
my $host =`hostname`.`date`;
print "VGINFO v 1.0\n";
print "LVM Managed Storage Information for $host \n";
print "\n";
print "LVM LVM Mirr Allocated Total Free\n";
print "Type Object Name Count (Mbytes) (Mbytes) (Mbytes)\n";
print "---- --------------------------- ----- -------- -------- --------\n";
foreach $_ (`/usr/sbin/vgdisplay -v`) {
if (/^(\s*\w\w) Name\s+(\S+)/) {
$type = $1;
$name = $2;
$name =~ s/\/dev//;
}
$pe = $1 if (/^PE Size \(Mbytes\)\s+(\w+)/);
$alloc = $1 if (/Allo.* PE\s+(\w+)/);
$total = $1 if (/Total PE\s+(\w+)/);
$free = $1 if (/Free PE\s+(\w+)/);
$s = $1 if (/Used PV\s+(\w+)/);
if (/^$/) {
if ($alloc + $total + $free) {
printf ("%-6s%-30s%3s%12d%9d%9d\n",
$type, $name, ($s)?$s :" ", $pe * $alloc, $pe * $total, $pe * $free);
} else { print "\n" } ;
$name = $type = " ";
$alloc = $total = $free = $s = 0;
}
}
Hakuna Matata.
Hein van den Heuvel
Honored Contributor

Re: VG Info script

Along similar lines (but better :-) check out the script I posted and attached to:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=640683

hth,
Hein.
Alzhy
Honored Contributor

Re: VG Info script

Hein,

You must be the original author of this script... Danke very much sire... we are using this scripten extensively...

Nelsonen
Hakuna Matata.