Hi,

The Perl script (shown further down below) gives me the following
output (without the comments).
Please note that this is not the complete output, I only show the
necessary detail for sake of clarity.

emcpowera        sdbd sddg sdfj sdhm       #  <- [1st foreach loop output]
emcpoweraa      sdae sdch sdek sdgn      # These the available
emcpower disks and their associate devices
emcpowerbc      sdb sdbe sddh sdfk
emcpowerc        sdbb sdde sdfh sdhk
emcpowerd        sdba sddd sdfg sdhj
emcpowera1      /dwpdb006                      #  <- [2nd foreach loop output]
emcpoweraa1    /dwpdb033                      # These are the local
emcpower* disk paritions and their local mount points.
emcpowerbc1    /s00_11                          # Note that the
emcpowerbc disk has 2 partitions, 1 and 2 below.
emcpowerbc2    /utl_file_dir
emcpowerc1      /odsdb006
emcpowerd1      /odsdb005

What I would like to do is to compare what (emcpower\w+\d) partitions
(seen from the output of the 2nd foreach loop), where mounted against
the available list of the (emcpower\w+) disk devices (found in the 1st
output) and then match on the (emcpower\w+) disk found (from 1st
output). The result of the output of the matched partition found (2nd
output) must concatenate to the result of the emcpower disk (1st
output), and then also show the (emcpower\w+) disks (from 1st output)
that wasn't matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera
(from 1st output) and display the result as follow:

    emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks that wasn't matched by a
(emxpower\w+\d) partition, to then display that normally like ie:

     emcpowerz sdbd sddg sdfj sdhm

If there are more than one (emcpower\w+\d) partition, to display the
output for example like this:

     emcpowerbc      sdb sdbe sddh sdfk  emcpowerbc1 /s00_11

emcpowerbc2 /utl_file_dir

I have included comments in the script to make it as clear as possible.

I can send the raw input for both $powermt and $mount if you need
them, just let me know.

==================================================================

<---script begin--->
#!/usr/bin/perl

use strict;
use warnings;

my $powermt = '/sbin/powermt display dev=all';
my $mount = '/bin/mount';

open my $emcDisks, '-|', $powermt or die "Could not execute powermt: $!";
open my $localDisks, '-|', $mount or die "Could not execute mount: $!";

my ($emcDevices, $localSdDevices);
my (@allLocalEmcDisks, @allLocalSdDisks, @allLocalMountedDevices);
my (%allEmcMountedDisks, %allLocalMountedDisks);

# Locate all available emcpower* disks and all sd* disks associated
with each EMC PowerPath disk.
while (my $i = <$emcDisks>) {
 if ( $i =~ /name=(emcpower\w+)/ ) {
   $emcDevices = $1; # $1 = emcpowerbc
 } elsif ( $i =~ /\blpfc\s+(sd\w+)/ ) { # $i = (sdb, sdbe, sddh, sdfk)
   push @{$allEmcMountedDisks{$emcDevices}}, $1; # hash =>
emcpowerbc[sdb, sdbe, sddh, sdfk]
 }
        # Locate all local mounted /dev/emcpower* partitions and all
local mounted /dev/sd* disk partitions
        while (my $b = <$localDisks>) {
                if ($b =~ /\/dev\/(emcpower\w+\d)/) {
                        push @allLocalMountedDevices, $1; # $1 = emcpowerbc1
                        @allLocalEmcDisks = split (/\s+/, $b); # $b =
/dev/emcpowerbc1 on /s00_11 type ext3 (rw,acl,user_xattr)
                        push @{$allLocalMountedDisks{$1}},
$allLocalEmcDisks[2]; # hash => [emxpowerbc1, /s00_11]
                } elsif ($b =~ /\/dev\/(sd\w+\d)/) {
                        push @allLocalMountedDevices, $1; # $1 = sdi1
                        @allLocalSdDisks = split (/\s+/, $b); # $b =
/dev/sdi1 on /dwpdb039 type ext3 (rw,acl,user_xattr)
                        push @{$allLocalMountedDisks{$1}},
$allLocalSdDisks[2]; # hash => [sdi, /dwpdb039]
                }
        }
}

# [1st foreach loop]
# Print each available emcpower* disks with their associated sd* disks
on the same line.
foreach my $i (sort keys %allEmcMountedDisks) {
        printf "%s\t%s\n", $i, join(' ', @{$allEmcMountedDisks{$i}});
}

# [2nd foreach loop]
# Print each local mouted disk found with it's mount point on the same line.
foreach my $i (sort keys %allLocalMountedDisks) {
        printf "\n%s %s\n", $i, join ' ', @{$allLocalMountedDisks{$i}};
}

<---script end--->
==================================================================

Regards,
Wernher Eksteen

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to