P
Phil Meyer
Part of the objective is to find a reliable way to discover the qlogic fiber
channel card WWN and which WWN(s) it connects to. This data is then stored
and compared to WWN data from the SAN fabric to determine which switch port
its connected to, and also which storage devices it is talking to.
Assumptions: Solaris systems, and explorer output as only source.
All of that aside, this is indeed a generic type issue, ie: is it ever
'better' to jump out to the shell for a quick and dirty, vs learning the
'better way' in perl. Honestly, this may be embarrassing to me, but it
is troublesome to look at a problem and have my mind see hundreds of lines
of perl code, or a few simple lines of shell commands.
OK here is the detail: The filenames are consistant and start with
luxadm_display_
There can be over 34,000 lines returned.
The function here is pretty self contained, so that this should be a
pretty clear example. And this style of C programming was fashionable
before most of you were born, so please try to limit the comments about
where curlies go. Thanks!
#!/usr/bin/perl -w
$ENV{'ORACLE_HOME'} = "/oracle/product/8.1.7a";
use File::stat qwFIELDS);
use DBI;
use strict;
get_WWN_sun()
{
my $cmd = "";
my $g = "";
my @data = "";
my $lun = "";
my $host_port = "";
my $i = 0 ;
my $line = "";
my $loc = "/export/data/explorer/blah_blah_blah/disks/luxadm_display*";
# This is the code in question -- How do do this as well in perl
# grep each half into seperate files, then paste them together.
$cmd = "grep -h \"LUN path port WWN\" $loc > /tmp/LUNs";
@data = system($cmd);
$cmd = "grep -h \"Host controller port WWN\" $loc > /tmp/Hosts";
@data = system($cmd);
$cmd = "paste /tmp/LUNs /tmp/Hosts | sort -u";
@data = `$cmd`;
# At this point I have boilded thousands of lines of data to just a couple.
# what is the better way?
# From here down is just database stuff, and yes it would be better to
# bind the variables, but the data is known and there are never special chars
# db connections are global
for ( @data )
{
($g,$g,$g,$g,$lun,$g,$g,$g,$g,$host_port) = split();
$line = "SELECT count(*) from WWN where
system like \'$host\' and
lun like \'$lun\'";
$i = $dbh->selectrow_array($line);
if ( $i == 0 )
{
$line = "INSERT INTO WWN VALUES
( \'$host\',\'$lun\',\'$host_port\',\'\',\'$drvr\',\'\' )";
print $line;
$sth0 = $dbh->prepare($line);
$sth0->execute();
}
else
{
$line = "UPDATE WWN SET
host_port = \'$host_port\',
driver = \'$drvr\'
where
system = \'$host\' and
lun = \'$lun\'";
print $line;
$sth0 = $dbh->prepare($line);
$sth0->execute();
}
}
}
channel card WWN and which WWN(s) it connects to. This data is then stored
and compared to WWN data from the SAN fabric to determine which switch port
its connected to, and also which storage devices it is talking to.
Assumptions: Solaris systems, and explorer output as only source.
All of that aside, this is indeed a generic type issue, ie: is it ever
'better' to jump out to the shell for a quick and dirty, vs learning the
'better way' in perl. Honestly, this may be embarrassing to me, but it
is troublesome to look at a problem and have my mind see hundreds of lines
of perl code, or a few simple lines of shell commands.
OK here is the detail: The filenames are consistant and start with
luxadm_display_
There can be over 34,000 lines returned.
The function here is pretty self contained, so that this should be a
pretty clear example. And this style of C programming was fashionable
before most of you were born, so please try to limit the comments about
where curlies go. Thanks!
#!/usr/bin/perl -w
$ENV{'ORACLE_HOME'} = "/oracle/product/8.1.7a";
use File::stat qwFIELDS);
use DBI;
use strict;
get_WWN_sun()
{
my $cmd = "";
my $g = "";
my @data = "";
my $lun = "";
my $host_port = "";
my $i = 0 ;
my $line = "";
my $loc = "/export/data/explorer/blah_blah_blah/disks/luxadm_display*";
# This is the code in question -- How do do this as well in perl
# grep each half into seperate files, then paste them together.
$cmd = "grep -h \"LUN path port WWN\" $loc > /tmp/LUNs";
@data = system($cmd);
$cmd = "grep -h \"Host controller port WWN\" $loc > /tmp/Hosts";
@data = system($cmd);
$cmd = "paste /tmp/LUNs /tmp/Hosts | sort -u";
@data = `$cmd`;
# At this point I have boilded thousands of lines of data to just a couple.
# what is the better way?
# From here down is just database stuff, and yes it would be better to
# bind the variables, but the data is known and there are never special chars
# db connections are global
for ( @data )
{
($g,$g,$g,$g,$lun,$g,$g,$g,$g,$host_port) = split();
$line = "SELECT count(*) from WWN where
system like \'$host\' and
lun like \'$lun\'";
$i = $dbh->selectrow_array($line);
if ( $i == 0 )
{
$line = "INSERT INTO WWN VALUES
( \'$host\',\'$lun\',\'$host_port\',\'\',\'$drvr\',\'\' )";
print $line;
$sth0 = $dbh->prepare($line);
$sth0->execute();
}
else
{
$line = "UPDATE WWN SET
host_port = \'$host_port\',
driver = \'$drvr\'
where
system = \'$host\' and
lun = \'$lun\'";
print $line;
$sth0 = $dbh->prepare($line);
$sth0->execute();
}
}
}