Commands.pm / @preserved_raid

Thomas Neumann blacky+fai at fluffbunny.de
Fri Aug 29 14:28:05 CEST 2014


Hello Kerim

Can you please explain the following line from Commands.pm?
  my $tmp_vg = `pvdisplay $raid | grep "VG Name" | grep -o "vg[0-9]"`;

Does this really mean you only consider volume groups with a name of 
'vg<digit>....' as valid values for $tmp_vg?


This is how I would do it. Maybe there is something I'm missing.

#!/usr/bin/perl

use strict;
use warnings;

my $raid = shift;

# ------------------- the code -------------------------
# fetch the pvdisplay output
my @output = `pvdisplay $raid`;
chomp @output;

# iterate output, looking for volume group name
my $tmp_vg;
for my $line (@output) {
  if ($line =~ /\A \s+ VG[ ]Name \s+ (.+) \z/xms) {
    # found a matching line - extract vg name
    $tmp_vg = $1;
  }
}

defined $tmp_vg
  or croak("Unable to determine volume group for '$raid'");
# ------------------- the code -------------------------

print "$raid -> $tmp_vg\n";



bye
thomas


More information about the linux-fai-devel mailing list