Wernher Eksteen wrote:
Hi,
Hello,
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.
==================================================================
The inner while loop and the outer while loop do not have any variables
in common. But that is not the problem.
The inner while loop only executes *once* because once the filehandle
reaches end-of-file it cannot read any more from that filehandle.
But it doesn't have to because no variables are used between the two
while loops. You probably want something like this:
#!/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: $!";
my ( $emcDevices, %allEmcMountedDisks );
# Locate all available emcpower* disks and all sd* disks associated with
each EMC PowerPath disk.
while ( my $i = <$emcDisks> ) {
if ( $i =~ /name=(emcpower[a-z]+)/ ) {
$emcDevices = $1; # $1 = emcpowerbc
}
elsif ( $i =~ /\blpfc\s+(sd[a-z]+)/ ) { # $i = (sdb, sdbe,
sddh, sdfk)
push @{ $allEmcMountedDisks{ $emcDevices } }, $1; #
hash => emcpowerbc[sdb, sdbe, sddh, sdfk]
}
}
close $emcDisks or warn $! ? "Error closing '$powermt' pipe: $!"
: "Exit status $? from '$powermt'";
# [1st foreach loop]
# Print each available emcpower* disks with their associated sd* disks
on the same line.
for my $i ( sort keys %allEmcMountedDisks ) {
print "$i\t@{$allEmcMountedDisks{$i}}\n";
}
open my $localDisks, '-|', $mount or die "Could not execute $mount: $!";
my %allLocalMountedDisks;
# Locate all local mounted /dev/emcpower* partitions and all local
mounted /dev/sd* disk partitions
while ( my $b = <$localDisks> ) {
if ( $b =~ m{/dev/((?:emcpower|sd)[a-z]+[1-9])\s+on\s+(/\w+)} ) {
# $b = /dev/emcpowerbc1 on /s00_11 type ext3
(rw,acl,user_xattr)
# hash => [emxpowerbc1, /s00_11]
# $b = /dev/sdi1 on /dwpdb039 type ext3 (rw,acl,user_xattr)
# hash => [sdi, /dwpdb039]
push @{ $allLocalMountedDisks{ $1 } }, $2;
}
}
close $localDisks or warn $! ? "Error closing $mount pipe: $!"
: "Exit status $? from $mount";
# [2nd foreach loop]
# Print each local mouted disk found with it's mount point on the same line.
for my $i ( sort keys %allLocalMountedDisks ) {
print "\n$i @{$allLocalMountedDisks{$i}}\n";
}
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/