I know close to nothing about Perl. This script was created on RHEL 5 and I wanted the functionality to be extended to RHEL 6.
In regards to our script the significant differences between RHEL 5 and 6 are:
RHEL5
/dev/mpath -- path to multipath devices
\_ -- identifier for multipath device
RHEL6
/dev/mapper -- path to multipath devices
|- -- identifier for multipath device
`- -- identifier for multipath device
#!/usr/bin/perl
@rhelver = `cat /etc/redhat-release`;
$rhelver[0] =~ / (\d\.\d) /;
$RELEASE = $1;
# ARRAY OF HDS ARRAYS
$sxm_arrays = {
'726a'=>'ITSHDS05',
'71c9'=>'ITSHDS06',
'61bc'=>'ITSHDS04',
'4ed0'=>'ITSHDS01',
'5b68'=>'ITSHDS02',
'03da'=>'ORION1',
'03f6'=>'TITAN1',
'ac75'=>'ATLAS',
'ba9e'=>'CAPELLA',
'2924'=>'REGULUS'
};
# BUILD ARRAY BASED ON OUTPUT FROM multipath COMMAND
open MPATH,"multipath -ll -v2|" or die "can't fork: $!";
while (<MPATH>) {
chomp;
if (m/^(mpath\d+) \(\w*(\w{4})\w{4}(\w{2})(\w{2})\) (\S+) /) {
$mpath_id="$sxm_arrays->{$2}_$3$4";
$ldev{$mpath_id}="$3:$4";
$array_id{$mpath_id}=$sxm_arrays->{$2};
$dm_id{$mpath_id}=$5;
$mpath_to_ldev{$mpath_id}=$1;
}
if (m/^([0-9a-zA-Z]+)\_(\w{2})(\w{2}) (dm-\d*) HIT/)
{
$mpath_id="$1_$2$3";
$ldev{"$1_$2$3"}="$2:$3";
$array_id{"$1_$2$3"}=$1;
$dm_id{"$1_$2$3"}=$4;
}
if ($RELEASE >= 6.0) {
$lun_size{$mpath_id}=$1 if m/size=([0-9A-Z\.]+)/;
#$sub_path{$mpath_id}.=$1 if m/^ \|- [\d,\:]+ *(\w+ )/;
#$sub_path{$mpath_id}.=$1 if m/^ `- [\d,\:]+ *(\w+ )/;
$sub_path{$mpath_id}.=$1 if m/^ [\|`]- [\d,\:]+ *(\w+ )/;
}
else
{
$lun_size{$mpath_id}=$1 if m/\[size=([0-9A-Z\.]+)\]/;
$sub_path{$mpath_id}.=$1 if m/ \\\_ [\d,\:]+ *(\w+ )/;
}
}
close MPATH;
%mpath_to_ldev=reverse %mpath_to_ldev;
if ($RELEASE >= 6.0) {
open B,"ls -lL /dev/mapper|" or die "can't fork: $!";
}
else
{
open B,"ls -lL /dev/mpath|" or die "can't fork: $!";
}
while (<B>) {
chmop;
$majmin{"$1,$2"}=$3 if m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(\w+\_\w+)/;
if(m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(mpath\w+)p1/){
$majmin{"$1,$2"}=$mpath_to_ldev{$3}."p1";
}
elsif (m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(mpath\w+)/){
$majmin{"$1,$2"}=$mpath_to_ldev{$3};
}
}
close B;
# The following is independent of RHEL version
%rmajmin=reverse %majmin;
open C,"ls -l /dev/oracleasm/disks|" or die "can't fork: $!";
while (<C>) {
chmop;
$asmdev{"$1,$2"}=$3 if m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(\S+)$/;
}
close C;
print (keys %sxm_arrays),"\n";
%mpath_to_ldev=reverse %mpath_to_ldev;
%$sxm_arrays=reverse %$sxm_arrays;
@sorted = sort { $asmdev{$a} cmp $asmdev{$b} } keys %asmdev;
format STDOUT=
@<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<@<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<@<<<<@<<<<<@<<<<<@<<<<<<<@*
$a, $dgname $b, $c, $d, $e, $f, $g, $h, $i, $j
.
$_='ASM_DEV_NAME ASM_DG PATH DevID D-Path DM SER LDEV SIZE D-DevID SUBPATH';
($a,$dgname,$b,$c,$d,$e,$f,$g,$h,$i,$j)=split;
write (STDOUT);
foreach (@sorted) {
($a,$b,$c)=($asmdev{$_},$majmin{$_},$_);
$dgname=`dd if=/dev/oracleasm/disks/$a bs=8 skip=13 count=4 2>/dev/null|strings`;
$_=$majmin{$_};m/([a-zA-Z0-9]+_\w{4})/;$_=$1;
($d,$e,$f,$g,$h,$i,$j)=($_,$dm_id{$_},$sxm_arrays->{$array_id{$_}},$ldev{$_},$lun_size{$_},$rmajmin{$_},$sub_path{$_});
if (scalar(keys %mpath_to_ldev) != 0) {
$d=$mpath_to_ldev{$d};
$b=~m/(.*)p1$/;
$b=$mpath_to_ldev{$1}."p1";
}
write (STDOUT);
}
RAW OUTPUT
===============
RHEL5
ORION1_1014 dm-4 HITACHI,OPEN-V
[size=800G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=1][active]
\_ 3:0:1:27 sdac 65:192 [active][ready]
\_ 4:0:1:27 sdcm 69:160 [active][ready]
\_ 7:0:0:27 sdew 129:128 [active][ready]
\_ 8:0:0:27 sdhg 133:96 [active][ready]
RHEL6
ORION1_3006 dm-2 HITACHI,OPEN-V
size=50G features='0' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
|- 2:0:0:0 sdc 8:32 active ready running
`- 0:0:0:0 sdj 8:144 active ready running
In regards to our script the significant differences between RHEL 5 and 6 are:
RHEL5
/dev/mpath -- path to multipath devices
\_ -- identifier for multipath device
RHEL6
/dev/mapper -- path to multipath devices
|- -- identifier for multipath device
`- -- identifier for multipath device
#!/usr/bin/perl
@rhelver = `cat /etc/redhat-release`;
$rhelver[0] =~ / (\d\.\d) /;
$RELEASE = $1;
# ARRAY OF HDS ARRAYS
$sxm_arrays = {
'726a'=>'ITSHDS05',
'71c9'=>'ITSHDS06',
'61bc'=>'ITSHDS04',
'4ed0'=>'ITSHDS01',
'5b68'=>'ITSHDS02',
'03da'=>'ORION1',
'03f6'=>'TITAN1',
'ac75'=>'ATLAS',
'ba9e'=>'CAPELLA',
'2924'=>'REGULUS'
};
# BUILD ARRAY BASED ON OUTPUT FROM multipath COMMAND
open MPATH,"multipath -ll -v2|" or die "can't fork: $!";
while (<MPATH>) {
chomp;
if (m/^(mpath\d+) \(\w*(\w{4})\w{4}(\w{2})(\w{2})\) (\S+) /) {
$mpath_id="$sxm_arrays->{$2}_$3$4";
$ldev{$mpath_id}="$3:$4";
$array_id{$mpath_id}=$sxm_arrays->{$2};
$dm_id{$mpath_id}=$5;
$mpath_to_ldev{$mpath_id}=$1;
}
if (m/^([0-9a-zA-Z]+)\_(\w{2})(\w{2}) (dm-\d*) HIT/)
{
$mpath_id="$1_$2$3";
$ldev{"$1_$2$3"}="$2:$3";
$array_id{"$1_$2$3"}=$1;
$dm_id{"$1_$2$3"}=$4;
}
if ($RELEASE >= 6.0) {
$lun_size{$mpath_id}=$1 if m/size=([0-9A-Z\.]+)/;
#$sub_path{$mpath_id}.=$1 if m/^ \|- [\d,\:]+ *(\w+ )/;
#$sub_path{$mpath_id}.=$1 if m/^ `- [\d,\:]+ *(\w+ )/;
$sub_path{$mpath_id}.=$1 if m/^ [\|`]- [\d,\:]+ *(\w+ )/;
}
else
{
$lun_size{$mpath_id}=$1 if m/\[size=([0-9A-Z\.]+)\]/;
$sub_path{$mpath_id}.=$1 if m/ \\\_ [\d,\:]+ *(\w+ )/;
}
}
close MPATH;
%mpath_to_ldev=reverse %mpath_to_ldev;
if ($RELEASE >= 6.0) {
open B,"ls -lL /dev/mapper|" or die "can't fork: $!";
}
else
{
open B,"ls -lL /dev/mpath|" or die "can't fork: $!";
}
while (<B>) {
chmop;
$majmin{"$1,$2"}=$3 if m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(\w+\_\w+)/;
if(m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(mpath\w+)p1/){
$majmin{"$1,$2"}=$mpath_to_ldev{$3}."p1";
}
elsif (m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(mpath\w+)/){
$majmin{"$1,$2"}=$mpath_to_ldev{$3};
}
}
close B;
# The following is independent of RHEL version
%rmajmin=reverse %majmin;
open C,"ls -l /dev/oracleasm/disks|" or die "can't fork: $!";
while (<C>) {
chmop;
$asmdev{"$1,$2"}=$3 if m/^b.* (\d+), *(\d+) +\S+ +\S+ +\S+ +(\S+)$/;
}
close C;
print (keys %sxm_arrays),"\n";
%mpath_to_ldev=reverse %mpath_to_ldev;
%$sxm_arrays=reverse %$sxm_arrays;
@sorted = sort { $asmdev{$a} cmp $asmdev{$b} } keys %asmdev;
format STDOUT=
@<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<@<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<@<<<<@<<<<<@<<<<<@<<<<<<<@*
$a, $dgname $b, $c, $d, $e, $f, $g, $h, $i, $j
.
$_='ASM_DEV_NAME ASM_DG PATH DevID D-Path DM SER LDEV SIZE D-DevID SUBPATH';
($a,$dgname,$b,$c,$d,$e,$f,$g,$h,$i,$j)=split;
write (STDOUT);
foreach (@sorted) {
($a,$b,$c)=($asmdev{$_},$majmin{$_},$_);
$dgname=`dd if=/dev/oracleasm/disks/$a bs=8 skip=13 count=4 2>/dev/null|strings`;
$_=$majmin{$_};m/([a-zA-Z0-9]+_\w{4})/;$_=$1;
($d,$e,$f,$g,$h,$i,$j)=($_,$dm_id{$_},$sxm_arrays->{$array_id{$_}},$ldev{$_},$lun_size{$_},$rmajmin{$_},$sub_path{$_});
if (scalar(keys %mpath_to_ldev) != 0) {
$d=$mpath_to_ldev{$d};
$b=~m/(.*)p1$/;
$b=$mpath_to_ldev{$1}."p1";
}
write (STDOUT);
}
RAW OUTPUT
===============
RHEL5
ORION1_1014 dm-4 HITACHI,OPEN-V
[size=800G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=1][active]
\_ 3:0:1:27 sdac 65:192 [active][ready]
\_ 4:0:1:27 sdcm 69:160 [active][ready]
\_ 7:0:0:27 sdew 129:128 [active][ready]
\_ 8:0:0:27 sdhg 133:96 [active][ready]
RHEL6
ORION1_3006 dm-2 HITACHI,OPEN-V
size=50G features='0' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
|- 2:0:0:0 sdc 8:32 active ready running
`- 0:0:0:0 sdj 8:144 active ready running
Comments
Post a Comment