Add files via upload

pvs.pl: show all PVOLs & option --active added 
lvs.pl: added lv extents
This commit is contained in:
Patrick Van der Veken 2016-06-27 11:04:07 +02:00 committed by GitHub
parent afecdd0ec0
commit 7a170b92c2
2 changed files with 104 additions and 59 deletions

View File

@ -72,8 +72,8 @@ unless ($options{'size'}) {
}; };
# print header # print header
printf STDOUT ("\n%-30s %-12s %-17s %-7s %-17s %-7s %-8s %-8s\n", printf STDOUT ("\n%-30s %-12s %-17s %-7s %-7s %-17s %-7s %-8s %-8s\n",
"LV", "VG", "Status", "Size", "Permissions", "Mirrors", "Stripes", "Allocation"); "LV", "VG", "Status", "Size", "Extents", "Permissions", "Mirrors", "Stripes", "Allocation");
# fetch LVOLs # fetch LVOLs
if ($options{'vg'}) { if ($options{'vg'}) {
@ -95,7 +95,7 @@ foreach my $lvol (@vgdisplay) {
foreach my $lv_entry (@lvdisplay) { foreach my $lv_entry (@lvdisplay) {
my ($vg_name, $lv_status, $lv_perm, $lv_alloc) = ("","","",""); my ($vg_name, $lv_status, $lv_perm, $lv_alloc) = ("","","","");
my ($lv_mirrors, $lv_stripes, $lv_size) = (0,0,0); my ($lv_mirrors, $lv_stripes, $lv_size, $lv_extent) = (0,0,0,0);
my @lv_data = split (/:/, $lv_entry); my @lv_data = split (/:/, $lv_entry);
@ -109,15 +109,17 @@ foreach my $lvol (@vgdisplay) {
$lv_stripes = $1 if ($lv_field =~ m%^stripes=(.*)%); $lv_stripes = $1 if ($lv_field =~ m%^stripes=(.*)%);
$lv_alloc = $1 if ($lv_field =~ m%^allocation=(.*)%); $lv_alloc = $1 if ($lv_field =~ m%^allocation=(.*)%);
$lv_size = $1 if ($lv_field =~ m%^lv_size=(.*)%); $lv_size = $1 if ($lv_field =~ m%^lv_size=(.*)%);
$lv_extent = $1 if ($lv_field =~ m%^current_le=(.*)%);
} }
# 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 %-8s %-8s\n", printf STDOUT ("%-30s %-12s %-17s %-7d %-7d %-17s %-7s %-8s %-8s\n",
${lv_name}, ${lv_name},
${vg_name}, ${vg_name},
${lv_status}, ${lv_status},
${lv_size}, ${lv_size},
${lv_extent},
${lv_perm}, ${lv_perm},
${lv_mirrors}, ${lv_mirrors},
${lv_stripes}, ${lv_stripes},
@ -179,3 +181,4 @@ S< >Show logical volume size in MB or GB (default is GB).
@(#) 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] @(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]
@(#) 2016-06-27: VRF 1.0.2: added lv extents [Patrick Van der Veken]

View File

@ -40,58 +40,35 @@ $|++;
my ($os, $version, $footer); my ($os, $version, $footer);
my %options; my %options;
my (@vgdisplay, @pvdisplay); my (@pvol, @vgdisplay);
#****************************************************************************** #******************************************************************************
# MAIN routine # SUBroutines
#****************************************************************************** #******************************************************************************
# where and what am I? sub parse_pvols {
die ("ERROR: must be invoked as root\n") if ($<);
($os, $version) = (uname())[0,2];
die ("ERROR: only runs on HP-UX v11.31") unless ($os eq 'HP-UX' and $version eq 'B.11.31');
# process command-line options my @pvol = @_;
if ( @ARGV > 0 ) { my @pvdisplay;
Getopt::Long::Configure('prefix_pattern=(--|-|\/)', 'bundling', 'no_ignore_case');
GetOptions( \%options,
qw(
help|h|?
size|s=s
vg|g=s
));
}
# check options
if ($options{'help'}) {
pod2usage(-verbose => 3);
exit (0);
};
unless ($options{'size'}) {
$options{'size'} = 'GB';
};
# print header unless (@pvol) {
printf STDOUT ("\n%-20s %-10s %-15s %-7s %-8s %-8s %-8s\n", print "-- no disks found --\n";
"PV", "VG", "Status", "PE Size", "PV Size", "PV Free", "Stale PE"); return;
}
# fetch LVOLs foreach my $pvol (@pvol) {
if ($options{'vg'}) {
@vgdisplay = `/usr/sbin/vgdisplay -vF ${options{'vg'}} 2>/dev/null | grep "^pv_name"`;
} else {
@vgdisplay = `/usr/sbin/vgdisplay -vF 2>/dev/null | grep "^pv_name"`;
}
die "failed to execute: $!" if ($?);
# loop over PVOLs my $pv_lvm = 1;
foreach my $pvol (@vgdisplay) {
my $pv_name = (split (/=/, (split (/:/, $pvol))[0]))[1]; chomp ($pvol);
@pvdisplay = `/usr/sbin/pvdisplay -F ${pv_name} 2>/dev/null`; @pvdisplay = `/usr/sbin/pvdisplay -F /dev/disk/${pvol} 2>&1`;
die "failed to execute: $!" if ($?); $pv_lvm = 0 if ($?) and (grep (/cannot display physical volume/i, @pvdisplay));
# loop over pvdisplay # loop over pvdisplay
if ($pv_lvm) {
foreach my $pv_entry (@pvdisplay) { foreach my $pv_entry (@pvdisplay) {
my ($vg_name, $pv_status)= ("",""); my ($vg_name, $pv_status)= ("","");
@ -117,8 +94,8 @@ foreach my $pvol (@vgdisplay) {
$pv_free /= 1024 unless ($options{'size'} =~ /MB/i); $pv_free /= 1024 unless ($options{'size'} =~ /MB/i);
# report data # report data
printf STDOUT ("%-20s %-10s %-15s %-7d %-8d %-8d %-8d\n", printf STDOUT ("%-20s %-12s %-15s %-7d %-8d %-8d %-8d\n",
${pv_name}, "/dev/disk/${pvol}",
${vg_name}, ${vg_name},
${pv_status}, ${pv_status},
${pv_size_pe}, ${pv_size_pe},
@ -126,12 +103,71 @@ foreach my $pvol (@vgdisplay) {
${pv_free}, ${pv_free},
${pv_stale_pe}) ${pv_stale_pe})
} }
} else {
unless ($options{'active'}) {
printf STDOUT ("%-20s %-12s %-15s\n", "/dev/disk/${pvol}",
"n/a",
"not active/not LVM");
}
}
}
}
#******************************************************************************
# MAIN routine
#******************************************************************************
# where and what am I?
die ("ERROR: must be invoked as root\n") if ($<);
($os, $version) = (uname())[0,2];
die ("ERROR: only runs on HP-UX v11.31") unless ($os eq 'HP-UX' and $version eq 'B.11.31');
# process command-line options
if ( @ARGV > 0 ) {
Getopt::Long::Configure('prefix_pattern=(--|-|\/)', 'bundling', 'no_ignore_case');
GetOptions( \%options,
qw(
help|h|?
size|s=s
vg|g=s
active|a
));
}
# check options
if ($options{'help'}) {
pod2usage(-verbose => 3);
exit (0);
};
unless ($options{'size'}) {
$options{'size'} = 'GB';
};
# print header
printf STDOUT ("\n%-20s %-12s %-15s %-7s %-8s %-8s %-8s\n",
"PV", "VG", "Status", "PE Size", "PV Size", "PV Free", "Stale PE");
# fetch PVOLs (non-boot)
if ($options{'vg'}) {
@pvol = `/usr/sbin/vgdisplay -vF "/dev/${options{'vg'}}" 2>/dev/null | grep "^pv_name" | cut -f1 -d':' | cut -f2 -d'=' | cut -f4 -d '/'`;
die "failed to execute: $!" if ($?);
parse_pvols (@pvol);
} else {
@pvol = `/usr/sbin/ioscan -kFN -C disk 2>/dev/null | cut -f9,13 -d':' | tr -d ':'`;
die "failed to execute: $!" if ($?);
parse_pvols (@pvol);
# fetch PVOLs (boot)
print "\n-- Boot disk(s):\n";
@pvol = `/usr/sbin/lvlnboot -v 2>/dev/null | grep 'Boot Disk' | awk '{ print \$1 }' | cut -f4 -d '/'`;
die "failed to execute: $!" if ($?);
parse_pvols (@pvol);
} }
# footer # footer
$footer = qq{ $footer = qq{
Note 1: 'PE Size' values are expressed in MB Note 1: 'PE Size' values are expressed in MB
Note 2: 'PV Size' & 'PV FRee' values are expressed in GB by default (see --help) Note 2: 'PV Size' & 'PV Free' values are expressed in GB by default (see --help)
Note 3: more detailed information can be obtained by running the pvdisplay(1M), vgdisplay(1M), lvdisplay(1M) commands Note 3: more detailed information can be obtained by running the pvdisplay(1M), vgdisplay(1M), lvdisplay(1M) commands
}; };
@ -158,6 +194,7 @@ pvs.pl - Show physical volume information in a terse way (Linux style).
pvs.pl [-h|--help] pvs.pl [-h|--help]
[(-g|--vg)=<vg_name>] [(-g|--vg)=<vg_name>]
[(-s|--size)=<MB|GB>] [(-s|--size)=<MB|GB>]
[(-a|--active)]
=head1 OPTIONS =head1 OPTIONS
@ -167,9 +204,13 @@ pvs.pl - Show physical volume information in a terse way (Linux style).
S< >Show the help page. S< >Show the help page.
=item -a | --active
S< >Hide non-active and non-LVM disks
=item -g | --vg =item -g | --vg
S< >Display physical volumes for a specific volume group. S< >Display physical volumes for a specific volume group. Volume group name should be specified without the "/dev/" prefix
=item -s | --size =item -s | --size
@ -183,3 +224,4 @@ S< >Show physical volume size in MB or GB (default is GB).
@(#) 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] @(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]
@(#) 2016-04-27: VRF 1.1.0: show all PVOLs & option --active added [Patrick Van der Veken]