1748054 Members
5235 Online
108758 Solutions
New Discussion юеВ

Re: scripting help

 
SOLVED
Go to solution
George Chechakunnil
Frequent Advisor

scripting help

Hello Admins,

I am trying to write a script that will give me the Free PE and PE Sizeon all VG's except /dev/vg00 on close to 100 servers

i have the ouput of #vgdisplay -v from all the servers copied up

how can i grep/ sed or awk only the VG Name, PE Size and Free PE lines?

eg
VG Name /dev/vg00
VG Write Access read/write
VG Status available
Max LV 255
Cur LV 14
Open LV 14
Max PV 16
Cur PV 2
Act PV 2
Max PE per PV 4384
VGDA 4
PE Size (Mbytes) 16
Total PE 4340
Alloc PE 4340
Free PE 0
Total PVG 0
Total Spare PVs 0
Total Spare PVs in use 0



VG Name /dev/vgora
VG Write Access read/write
VG Status available
Max LV 255
Cur LV 1
Open LV 1
Max PV 16
Cur PV 2
Act PV 2
Max PE per PV 2489
VGDA 4
PE Size (Mbytes) 4
Total PE 4978
Alloc PE 3250
Free PE 1728
Total PVG 0
Total Spare PVs 0

I would like the output to look like

VG Name /dev/vgora
PE Size (Mbytes) 4
Free PE 1728


exlcude /dev/vg00 and get the 3 paremeters for other vgs.

thanks in advance

I am like a small boy picking up pebbles in god's vast shore of knowledge --- Sir Issac Newton
12 REPLIES 12
Sandman!
Honored Contributor
Solution

Re: scripting help

Try the command pipeline below:

# ls -1d /dev/vg* | grep -v vg00 | xargs vgdisplay 2>&- | egrep '(^VG N|^PE|^Free)'
AwadheshPandey
Honored Contributor

Re: scripting help

you can use ssh/rsh for all servers at one script with Sandman! one liner.
ssh hostname ls -1d /dev/vg* | grep -v vg00 | xargs vgdisplay 2>&- | egrep '(^VG N|^PE|^Free)'
It's kind of fun to do the impossible
George Chechakunnil
Frequent Advisor

Re: scripting help

Terrific.. It works

Actually i am doing this on a file. Here is the output. how can i exclude the 3 lines for /dev/vg00?



cat VGDISPLAY | egrep '(^VG N|^PE|^Free)'
VG Name /dev/vg00
PE Size (Mbytes) 16
Free PE 0
VG Name /dev/vgora
PE Size (Mbytes) 4
Free PE 1728
VG Name /dev/vgkctr8
PE Size (Mbytes) 4
Free PE 685
VG Name /dev/vgkctr9
PE Size (Mbytes) 4
Free PE 685
VG Name /dev/vgkdprd
PE Size (Mbytes) 4
Free PE 3446
VG Name /dev/vgkct10
PE Size (Mbytes) 4
Free PE 685
VG Name /dev/vgptprd
PE Size (Mbytes) 4
Free PE 3446
I am like a small boy picking up pebbles in god's vast shore of knowledge --- Sir Issac Newton
AwadheshPandey
Honored Contributor

Re: scripting help

hope that this will do all u need
cat filename|xargs -n10|grep -v vg00
It's kind of fun to do the impossible
James R. Ferguson
Acclaimed Contributor

Re: scripting help

Hi:

Actually i am doing this on a file. Here is the output. how can i exclude the 3 lines for /dev/vg00?

Either:

# vgdisplay -v|awk '/^VG Name|^PE|^Free/ {if (i++<3) {next};print}'

...or:

# awk '/^VG Name|^PE|^Free/ {if (i++<3) {next};print}' VGDISPLAY

...where (of course) "VGDISPLAY" in all uppercase letters is the name of your file.

Regards!

...JRF...
Sandman!
Honored Contributor

Re: scripting help

# cat VGDISPLAY | egrep '(^VG N|^PE|^Free)' | sed -n '/vgora/,$ p'
Juan M Leon
Trusted Contributor

Re: scripting help

I use a script for my vg reports
and I get the following outpupt:
+++< /dev/vg01 >+++
/dev/vg01 PE size 4 Total allocated : 83.977 GB Available : 0.188 GB

LV Name Mir Size Stripe Stripe size Mount Point
/dev/vg01/lvol1 0 1000.000 MB 0 0 /usr/A
/dev/vg01/lvol10 0 200.000 MB 0 0 /oracle/A/A
/dev/vg01/lvol11 0 200.000 MB 0 0 /oracle/A/B
/dev/vg01/lvol12 0 2000.000 MB 0 0 /oracle/A/org
/dev/vg01/lvol13 0 16500.000 MB 0 0 /oracle/A/data1
/dev/vg01/lvol14 0 12000.000 MB 0 0 /oracle/A/data2
/dev/vg01/lvol15 0 12000.000 MB 0 0 /oracle/A/data3
/dev/vg01/lvol16 0 13500.000 MB 0 0 /oracle/A/data4
/dev/vg01/lvol2 0 5000.000 MB 0 0 /mnt/A
/dev/vg01/lvol3 0 5000.000 MB 0 0 /usr/a/A
/dev/vg01/lvol4 0 5000.000 MB 0 0 /oracle
/dev/vg01/lvol5 0 5000.000 MB 0 0 /oracle/age
/dev/vg01/lvol6 0 2000.000 MB 0 0 /oracle/A
/dev/vg01/lvol7 0 6000.000 MB 0 0 /oracle/A/64
/dev/vg01/lvol8 0 2000000 MB 0 0 /oracle/A/logA
/dev/vg01/lvol9 0 200.000 MB 0 0 /oracle/A/logB


As you see this report shows Lvol, Mirror if there is, # stripes, stripe size and mount point.
If you need to modify just to show the vg with out the lvol info use the following



#!/usr/bin/ksh
# 06/14/07 JML

if [ `uname -s` != "HP-UX" ] ; then
echo " This script was build to run on HPUX systems... Thank you ! "
exit 99
fi

# List of VG
for VG in `ls -d /dev/vg* | grep -v vg00`
do
echo "+++< ${VG} >+++"
vgdisplay $VG > /dev/null 2>&1

if [ $? -ne 0 ] ; then
echo " Volume group \"$VG\" does not exist in the "/etc/lvmtab" file, or is not active. "
else
vgdisplay $VG | awk '/VG Name/ {printf "%-17s ",$NF}
/PE Size \(Mbytes\)/ {PESZ=$NF;printf "PE size %-4s ",$NF}
/Total PE/ {printf "Total allocated :%8.3f GB ",((PESZ*$NF)/1024)}
/Free PE/ {printf "Available :%8.3f GB \n\n",((PESZ*$NF)/1024)}'


fi
done


Let me know if you need help
Juan M Leon
Trusted Contributor

Re: scripting help

oops forgot to include the other script with lvol information

#!/usr/bin/ksh
# 06/14/07 JML

if [ `uname -s` != "HP-UX" ] ; then
echo " This script was build to run on HPUX systems... Thank you ! "
exit 99
fi

# List of VG
for VG in `ls -d /dev/vg* | grep -v vg00`
do
echo "+++< ${VG} >+++"
vgdisplay $VG > /dev/null 2>&1

if [ $? -ne 0 ] ; then
echo " Volume group \"$VG\" does not exist in the "/etc/lvmtab" file, or is not active. "
else
vgdisplay $VG | awk '/VG Name/ {printf "%-17s ",$NF}
/PE Size \(Mbytes\)/ {PESZ=$NF;printf "PE size %-4s ",$NF}
/Total PE/ {printf "Total allocated :%8.3f GB ",((PESZ*$NF)/1024)}
/Free PE/ {printf "Available :%8.3f GB \n\n",((PESZ*$NF)/1024)}'

# List of lvol

printf " %-17s %-4s %10s %6s %10s %20s \n" "LV Name" "Mir" "Size" "Stripe" "Stripe size" "Mount Point"
for LVOL in `ls ${VG}/lvo*`
do
mount -p | egrep -e "$LVOL " > /dev/null
if [ $? -ne 0 ] ; then
MOUNTPOINT="not_found"
else
MOUNTPOINT=`mount -p | egrep "$LVOL " | awk '{print $2}'`
fi
lvdisplay ${LVOL} | awk '/LV Name/ {printf "%-17s ",$NF}
/Mirror copies/ {printf "%-5s ",$NF}
/LV Size \(Mbytes\)/ {printf "%10.3f MB ",$NF}
/Stripes/ {printf "%6s ",$NF}
/Stripe Size / {printf " %10s ",$NF}'
printf " %-20s \n" $MOUNTPOINT
done
printf " \n"
fi
done
Hein van den Heuvel
Honored Contributor

Re: scripting help

George,

Once you have those Name, Size and Free lines, don't you want to report them more nicely?

Please consider a slightly more elaborate script, for example along the lines of the perl example below, to really parse the input data and add some more value.

$ perl x.pl x.txt
Name Size Free Mbytes
---- ---- ---- ------
/dev/vgora 4 1728 6912


------------------ x.pl -------------------
#!/usr/bin/perl

use strict;
use warnings;
my ($name, $size, $free);
my $format = "%20s %4s %6s %6s\n";
printf $format, qw(Name Size Free Mbytes);
printf $format, qw(---- ---- ---- ------);
while (<>) {
$name = $1 if /^VG Name\s+(.*)$/;
$size = $1 if /^PE S.*\s(\d+)/;
if (/^Free PE\s+(\d+)$/) {
$free = $1;
printf ("%20s %4d %6d %6d\n", $name, $size, $free, $free*$size) unless $name =~ /vg00/
}
}
---------------------------

Hope this helps some,
Hein van den Heuvel (at gmail dot com)
HvdH Performance Consulting