#!/usr/bin/perl use strict; use warnings; # Author: David Morris # Version: $Id: ficonfig,v 1.1 2004/11/05 22:20:37 davey Exp $ # Purpose: Print fibre card port WWN and firmware versions # License: Released under the GNU Public Licence (GPL) # The terms of the GPL are available at: # http://www.gnu.org/licenses/gpl.html #use diagnostics; #use Data::Dumper; #use Getopt::Long; require 5.6.0; my (@prtpicl, @cfgadm, @fibrereport) ; if ($^O eq "solaris") { #print "Do Solaris Stuff\n"; my @prtpicl = prtpicl2array(); PrtpiclProc(@prtpicl); PrintReport(); } elsif ($^O eq "hpux") { #print "Do hp Stuff\n"; # Need to run as root on HP-UX to use fcmsutil checkforroot(); FCMSUtilProc(); PrintReport(); } elsif ($^O eq "linux") { print "Do linux Stuff\n"; my @prtpicl = prtpicl2array(); PrtpiclProc(@prtpicl); } else { return "Don't know how to stuff on platform $^O"; } sub checkforroot { if ( $> != 0 ) { die "ERROR: Need to run as root on platform: $^O \n"; } } sub FCMSUtilProc { my @devices = ioscan2array(); my ($cmdfh, $ctlr, $portwwn, $devfs, $version, $spare); my $command = "/opt/fcms/bin/fcmsutil"; foreach (@devices) { $ctlr = $_; open($cmdfh, "$command $ctlr |") or die "Cannot run $command: $!"; my @array =<$cmdfh>; $ctlr =~ s/\/dev\///; foreach my $line (@array) { if ($line =~ m/N_Port Port/) { ($spare, $portwwn) = split /=/,$line; $portwwn =~ s/^ 0x//; chomp($portwwn); } elsif ($line =~ m/Hardware Path/) { ($spare, $devfs) = split /=/,$line; $devfs =~ s/^ //; chomp($devfs); } elsif ($line =~ m/Driver Version/) { ($spare, $version) = split/=/,$line; $version =~ s/^ //; $version =~ s/PATCH_//; $version =~ s/: libtd.a ://; $version =~ s/\@\(#\) //; chomp($version); push @fibrereport, "$ctlr|$portwwn|$devfs|$version\n"; } } } } sub cfgadm2array { # Returns cfgadm -v as an array my $cmdfh; my $command = "/usr/sbin/cfgadm"; my $command_options = "-v"; open($cmdfh, "$command $command_options |") or die "Cannot run $command $command_options: $!"; my @cfgadm = <$cmdfh>; return @cfgadm; } sub ioscan2array { # HP Only # Returns ioscan as an array my ($cmdfh, $command, $command_options, @array, @devices); $command = "/usr/sbin/ioscan"; $command_options = "-funC fc"; open($cmdfh, "$command $command_options|") or die "Cannot run $command $command_options: $!"; @array = <$cmdfh>; foreach (@array) { if ( m/(\s+)(\/dev\/[a-z]*[0-9])/ ) { push @devices, $2; } } return @devices; } sub prtpicl2array { # Sun Only # Returns prtpicl as an array my ($cmdfh); my $command = "/usr/sbin/prtpicl"; my $command_options = "-v -c scsi-fcp"; open($cmdfh, "$command $command_options|") or die "Cannot run $command $command_options: $!"; my @prtpicl = <$cmdfh>; return @prtpicl; } sub PrtpiclProc { # Sun Only @cfgadm = cfgadm2array(); #print "this is cfgadm @cfgadm"; my $oldseparator = $/; my @prtpicl = @_; my $recordseparator = "^ SUNW,qlc "; my ($card, $line, $count, $version, $devfs, $portwwn, $firmware); foreach my $line (@prtpicl) { chomp($line); if ($line =~ m/(^ SUNW,qlc )/i){ $card = $1; $card =~ s/[\t\s]+//g; ++$count; } if ($line =~ m/^ :version\t (.*)/i){ $version = $1; $version =~ s/Host Adapter Driver:|FC-AL Host Adapter Driver://; } if ($line =~ m/^ :port-wwn\t (.*)/i){ $portwwn = $1; $portwwn =~ s/\s+//g; } if ($line =~ m/(^ :devfs-path\t .*)/i){ my $device = $1; my ($bob, $devfs) = split /\t/, $device; $devfs =~ s/ //g; my $ctlr = SunCfgadmProc($devfs); push @fibrereport, "$ctlr|$portwwn|$devfs|$version"; } } } sub SunCfgadmProc { # Sun Only my $cfg = shift; my $count = 0; my ($ctlr, $bobbins, $ctlrline); $cfg =~ s/\s+//g; $cfg = $cfg . "/"; #print "This is cfgadm: @cfgadm\n"; foreach (@cfgadm) { if ( /$cfg/ ) { my $prev= $count - 1; $ctlrline = $cfgadm[$prev]; ($ctlr, $bobbins) = split(/ /, $ctlrline); return $ctlr; } ++$count; } } sub PrintReport { my ($ctlr, $portwwn, $devfs, $version, $line); printf STDERR "%-4.4s %-18.18s %-32.32s %-24.24s\n","Ctlr","Port WWN","Device","F/Ware Version"; printf STDERR "-"x80; print STDERR "\n"; foreach $line (@fibrereport) { ($ctlr, $portwwn, $devfs, $version) = split /\|/, $line; printf "%-4.4s %-18.18s %-32.32s %-24.24s\n",$ctlr,$portwwn,$devfs, $version; } } __END__ =head1 NAME ficonfig =head1 SYNOPSIS List fibre controllers and their Port WWN =head1 DESCRIPTION ficonfig outputs a list of fibre controllers and their port WWN's =head1 OPTIONS none =head1 NOTES ficonfig is known to work with the following OS and fibrecards: *------------------------------------------* | O/S | Fibre Card | -------------------------------------------| | Solaris | Q-Logic/Crystal2 | | HP/UX 11.x | Tachyon 2 | *------------------------------------------* =head1 WARNINGS Solaris: o Make sure you have a look at Sun Bug Report ID: 4969197 if you are seeing duplicate WWNs HP-UX: o Must run as root on HP platforms