Add files via upload
pvs.pl: show all PVOLs & option --active added lvs.pl: added lv extents
This commit is contained in:
parent
afecdd0ec0
commit
7a170b92c2
@ -72,8 +72,8 @@ unless ($options{'size'}) {
|
||||
};
|
||||
|
||||
# print header
|
||||
printf STDOUT ("\n%-30s %-12s %-17s %-7s %-17s %-7s %-8s %-8s\n",
|
||||
"LV", "VG", "Status", "Size", "Permissions", "Mirrors", "Stripes", "Allocation");
|
||||
printf STDOUT ("\n%-30s %-12s %-17s %-7s %-7s %-17s %-7s %-8s %-8s\n",
|
||||
"LV", "VG", "Status", "Size", "Extents", "Permissions", "Mirrors", "Stripes", "Allocation");
|
||||
|
||||
# fetch LVOLs
|
||||
if ($options{'vg'}) {
|
||||
@ -95,7 +95,7 @@ foreach my $lvol (@vgdisplay) {
|
||||
foreach my $lv_entry (@lvdisplay) {
|
||||
|
||||
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);
|
||||
|
||||
@ -109,15 +109,17 @@ foreach my $lvol (@vgdisplay) {
|
||||
$lv_stripes = $1 if ($lv_field =~ m%^stripes=(.*)%);
|
||||
$lv_alloc = $1 if ($lv_field =~ m%^allocation=(.*)%);
|
||||
$lv_size = $1 if ($lv_field =~ m%^lv_size=(.*)%);
|
||||
$lv_extent = $1 if ($lv_field =~ m%^current_le=(.*)%);
|
||||
}
|
||||
# convert to GB if needed
|
||||
$lv_size /= 1024 unless ($options{'size'} =~ /MB/i);
|
||||
# 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},
|
||||
${vg_name},
|
||||
${lv_status},
|
||||
${lv_size},
|
||||
${lv_extent},
|
||||
${lv_perm},
|
||||
${lv_mirrors},
|
||||
${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-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]
|
128
lx-lvm/pvs.pl
128
lx-lvm/pvs.pl
@ -40,58 +40,35 @@ $|++;
|
||||
|
||||
my ($os, $version, $footer);
|
||||
my %options;
|
||||
my (@vgdisplay, @pvdisplay);
|
||||
my (@pvol, @vgdisplay);
|
||||
|
||||
|
||||
#******************************************************************************
|
||||
# MAIN routine
|
||||
# SUBroutines
|
||||
#******************************************************************************
|
||||
|
||||
# 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');
|
||||
sub parse_pvols {
|
||||
|
||||
# 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
|
||||
));
|
||||
}
|
||||
# check options
|
||||
if ($options{'help'}) {
|
||||
pod2usage(-verbose => 3);
|
||||
exit (0);
|
||||
};
|
||||
unless ($options{'size'}) {
|
||||
$options{'size'} = 'GB';
|
||||
};
|
||||
my @pvol = @_;
|
||||
my @pvdisplay;
|
||||
|
||||
# print header
|
||||
printf STDOUT ("\n%-20s %-10s %-15s %-7s %-8s %-8s %-8s\n",
|
||||
"PV", "VG", "Status", "PE Size", "PV Size", "PV Free", "Stale PE");
|
||||
unless (@pvol) {
|
||||
print "-- no disks found --\n";
|
||||
return;
|
||||
}
|
||||
|
||||
# fetch LVOLs
|
||||
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 ($?);
|
||||
foreach my $pvol (@pvol) {
|
||||
|
||||
# loop over PVOLs
|
||||
foreach my $pvol (@vgdisplay) {
|
||||
my $pv_lvm = 1;
|
||||
|
||||
my $pv_name = (split (/=/, (split (/:/, $pvol))[0]))[1];
|
||||
chomp ($pvol);
|
||||
|
||||
@pvdisplay = `/usr/sbin/pvdisplay -F ${pv_name} 2>/dev/null`;
|
||||
die "failed to execute: $!" if ($?);
|
||||
@pvdisplay = `/usr/sbin/pvdisplay -F /dev/disk/${pvol} 2>&1`;
|
||||
$pv_lvm = 0 if ($?) and (grep (/cannot display physical volume/i, @pvdisplay));
|
||||
|
||||
# loop over pvdisplay
|
||||
if ($pv_lvm) {
|
||||
|
||||
foreach my $pv_entry (@pvdisplay) {
|
||||
|
||||
my ($vg_name, $pv_status)= ("","");
|
||||
@ -117,8 +94,8 @@ foreach my $pvol (@vgdisplay) {
|
||||
$pv_free /= 1024 unless ($options{'size'} =~ /MB/i);
|
||||
|
||||
# report data
|
||||
printf STDOUT ("%-20s %-10s %-15s %-7d %-8d %-8d %-8d\n",
|
||||
${pv_name},
|
||||
printf STDOUT ("%-20s %-12s %-15s %-7d %-8d %-8d %-8d\n",
|
||||
"/dev/disk/${pvol}",
|
||||
${vg_name},
|
||||
${pv_status},
|
||||
${pv_size_pe},
|
||||
@ -126,12 +103,71 @@ foreach my $pvol (@vgdisplay) {
|
||||
${pv_free},
|
||||
${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 = qq{
|
||||
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
|
||||
|
||||
};
|
||||
@ -158,6 +194,7 @@ pvs.pl - Show physical volume information in a terse way (Linux style).
|
||||
pvs.pl [-h|--help]
|
||||
[(-g|--vg)=<vg_name>]
|
||||
[(-s|--size)=<MB|GB>]
|
||||
[(-a|--active)]
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
@ -167,9 +204,13 @@ pvs.pl - Show physical volume information in a terse way (Linux style).
|
||||
|
||||
S< >Show the help page.
|
||||
|
||||
=item -a | --active
|
||||
|
||||
S< >Hide non-active and non-LVM disks
|
||||
|
||||
=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
|
||||
|
||||
@ -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-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]
|
Loading…
x
Reference in New Issue
Block a user