Added major/minor number discovery in vgs

Smaller fixes
This commit is contained in:
patvdv 2016-05-01 19:47:22 +02:00
parent 9e53269f11
commit afecdd0ec0
3 changed files with 31 additions and 19 deletions

View File

@ -72,14 +72,14 @@ unless ($options{'size'}) {
}; };
# print header # print header
printf STDOUT ("\n%-30s %-12s %-17s %-6s %-10s %-7s %-8s %-8s\n", printf STDOUT ("\n%-30s %-12s %-17s %-7s %-17s %-7s %-8s %-8s\n",
"LV", "VG", "Status", "Size", "Permissions", "Mirrors", "Stripes", "Allocation"); "LV", "VG", "Status", "Size", "Permissions", "Mirrors", "Stripes", "Allocation");
# fetch LVOLs # fetch LVOLs
if ($options{'vg'}) { if ($options{'vg'}) {
@vgdisplay = `/usr/sbin/vgdisplay -vF ${options{'vg'}} | grep "^lv_name"`; @vgdisplay = `/usr/sbin/vgdisplay -vF ${options{'vg'}} 2>/dev/null | grep "^lv_name"`;
} else { } else {
@vgdisplay = `/usr/sbin/vgdisplay -vF | grep "^lv_name"`; @vgdisplay = `/usr/sbin/vgdisplay -vF 2>/dev/null | grep "^lv_name"`;
} }
die "failed to execute: $!" if ($?); die "failed to execute: $!" if ($?);
@ -88,7 +88,7 @@ foreach my $lvol (@vgdisplay) {
my $lv_name = (split (/=/, (split (/:/, $lvol))[0]))[1]; my $lv_name = (split (/=/, (split (/:/, $lvol))[0]))[1];
@lvdisplay = `/usr/sbin/lvdisplay -F ${lv_name}`; @lvdisplay = `/usr/sbin/lvdisplay -F ${lv_name} 2>/dev/null`;
die "failed to execute: $!" if ($?); die "failed to execute: $!" if ($?);
# loop over lvdisplay # loop over lvdisplay
@ -113,7 +113,7 @@ foreach my $lvol (@vgdisplay) {
# convert to GB if needed # convert to GB if needed
$lv_size /= 1024 unless ($options{'size'} =~ /MB/i); $lv_size /= 1024 unless ($options{'size'} =~ /MB/i);
# report data # report data
printf STDOUT ("%-30s %-12s %-17s %-7d %-17s %-7s %-2s %-5s\n", printf STDOUT ("%-30s %-12s %-17s %-7d %-17s %-7s %-8s %-8s\n",
${lv_name}, ${lv_name},
${vg_name}, ${vg_name},
${lv_status}, ${lv_status},
@ -178,3 +178,4 @@ S< >Show logical volume size in MB or GB (default is GB).
=head1 history =head1 history
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken] @(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
@(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]

View File

@ -77,9 +77,9 @@ printf STDOUT ("\n%-20s %-10s %-15s %-7s %-8s %-8s %-8s\n",
# fetch LVOLs # fetch LVOLs
if ($options{'vg'}) { if ($options{'vg'}) {
@vgdisplay = `/usr/sbin/vgdisplay -vF ${options{'vg'}} | grep "^pv_name"`; @vgdisplay = `/usr/sbin/vgdisplay -vF ${options{'vg'}} 2>/dev/null | grep "^pv_name"`;
} else { } else {
@vgdisplay = `/usr/sbin/vgdisplay -vF | grep "^pv_name"`; @vgdisplay = `/usr/sbin/vgdisplay -vF 2>/dev/null | grep "^pv_name"`;
} }
die "failed to execute: $!" if ($?); die "failed to execute: $!" if ($?);
@ -88,7 +88,7 @@ foreach my $pvol (@vgdisplay) {
my $pv_name = (split (/=/, (split (/:/, $pvol))[0]))[1]; my $pv_name = (split (/=/, (split (/:/, $pvol))[0]))[1];
@pvdisplay = `/usr/sbin/pvdisplay -F ${pv_name}`; @pvdisplay = `/usr/sbin/pvdisplay -F ${pv_name} 2>/dev/null`;
die "failed to execute: $!" if ($?); die "failed to execute: $!" if ($?);
# loop over pvdisplay # loop over pvdisplay
@ -182,3 +182,4 @@ S< >Show physical volume size in MB or GB (default is GB).
=head1 history =head1 history
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken] @(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
@(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]

View File

@ -31,6 +31,7 @@ use warnings;
use POSIX qw(uname); use POSIX qw(uname);
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
use Data::Dumper;
$|++; $|++;
@ -72,14 +73,14 @@ unless ($options{'size'}) {
}; };
# print header # print header
printf STDOUT ("\n%-10s %-5s %-5s %-20s %-8s %-8s %-10s %-10s %-10s\n", printf STDOUT ("\n%-15s %-5s %-5s %-20s %-8s %-8s %-10s %-10s %-10s %-12s\n",
"VG", "PVs", "LVs", "Status", "Version", "PE Size", "VG Size", "VG Free", "VG Max"); "VG", "PVs", "LVs", "Status", "Version", "PE Size", "VG Size", "VG Free", "VG Max", "VG Major/Minor");
# fetch vgdisplay # fetch vgdisplay
if ($options{'vg'}) { if ($options{'vg'}) {
@vgdisplay = `/usr/sbin/vgdisplay -F ${options{'vg'}}`; @vgdisplay = `/usr/sbin/vgdisplay -F ${options{'vg'}} 2>/dev/null`;
} else { } else {
@vgdisplay = `/usr/sbin/vgdisplay -F`; @vgdisplay = `/usr/sbin/vgdisplay -F 2>/dev/null`;
} }
die "failed to execute: $!" if ($?); die "failed to execute: $!" if ($?);
@ -87,7 +88,7 @@ die "failed to execute: $!" if ($?);
# loop over vgdisplay # loop over vgdisplay
foreach my $vg_entry (@vgdisplay) { foreach my $vg_entry (@vgdisplay) {
my ($vg_name, $vg_status, $vg_version)= ("","","n/a"); my ($vg_name, $vg_status, $vg_version, $lsvg, $vg_major, $vg_minor,) = ("","","n/a","","n/a","n/a");
my ($vg_total_pe, $vg_size_pe, $vg_free_pe, $vg_cur_pvs, $vg_cur_lvs, $vg_max_pe) = (0,0,0,0,0,0); my ($vg_total_pe, $vg_size_pe, $vg_free_pe, $vg_cur_pvs, $vg_cur_lvs, $vg_max_pe) = (0,0,0,0,0,0);
my ($vg_size, $vg_free, $vg_max) = (0,0,0); my ($vg_size, $vg_free, $vg_max) = (0,0,0);
@ -118,9 +119,15 @@ foreach my $vg_entry (@vgdisplay) {
$vg_max = $vg_max_pe * $vg_size_pe; $vg_max = $vg_max_pe * $vg_size_pe;
$vg_max /= 1024 unless ($options{'size'} =~ /MB/i); $vg_max /= 1024 unless ($options{'size'} =~ /MB/i);
} }
# get minor number
$lsvg = `/usr/bin/ls -l /dev/${vg_name}/group 2>/dev/null`;
unless ($?) {
$vg_major = (split (/\s+/, $lsvg))[4];
$vg_minor = (split (/\s+/, $lsvg))[5];
}
# report data # report data
printf STDOUT ("%-10s %-5s %-5s %-20s %-8s %-8d %-10d %-10d %-10d\n", printf STDOUT ("%-15s %-5s %-5s %-20s %-8s %-8d %-10d %-10d %-10d %3s/%-8s\n",
${vg_name}, ${vg_name},
${vg_cur_pvs}, ${vg_cur_pvs},
${vg_cur_lvs}, ${vg_cur_lvs},
@ -129,7 +136,9 @@ foreach my $vg_entry (@vgdisplay) {
${vg_size_pe}, ${vg_size_pe},
${vg_size}, ${vg_size},
${vg_free}, ${vg_free},
${vg_max}) ${vg_max},
${vg_major},
${vg_minor})
} }
# footer # footer
@ -186,3 +195,4 @@ S< >Show volume group sizes in MB or GB (default is GB).
=head1 history =head1 history
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken] @(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
@(#) 2016-04-27: VRF 1.0.1: added 'VG Major/Minor' [Patrick Van der Veken]