getting LUN IDs via the ‘format’ utility in Solaris

This one’s long overdue and it’s only now that I got to post it:

My team mate was doing server inventory for some DR exercise a month ago. One of his tasks was to jot down the LUN IDs. Like what he said, there are a lot of ways to determine the LUN ID. One way to do that would be to use the ‘format’ utility to determine the ID for nonSVC LUNs, in which I was also taught on how to do it. Having to manually check on each single SAN disk’s LUN ID is a very daunting task if done manually.

I got asked if I could code a script that would help in getting the task done faster and/or automate it. I thought it would be a good coding exercise. A shell script would have done the job, but perl is more fun. The script’s below, it’s actually pretty short compared to doing it in shell script:

#!/usr/bin/perl

#print out a label
print "DISK#\t DISKNAME\t\t\t LUNID\t\n";

#initially run 'format' so we can get a list of all the disks on the system and store
#its output to something we can referrence later
@i=`echo '' |format `;

#if you know what your local drive's names are you can "grep -v" 
#them e.g. replace the command above with:
#@i=`echo ''|format |grep -v SUN`;
#let's start parsing the output from the format utility command defined above(@a)

foreach (@i)
{
#only match lines that contain the disk numbers e.g.(2. 3. 4. 5. and so forth)
# 2. c3t50060E8003A8F808d1 <HITACHI-OPEN-E*36-SUN-2106 cyl 65533 alt 2 hd 60 sec 260>
# 3. c3t50060E8003A8F808d2 <HITACHI-OPEN-E*3-SUN-2106 cyl 59275 alt 2 hd 15 sec 96>
	if (/(\d){1,10}\./)
	{
	     	#store the matched value to a variable so we can referrence it later
		$m = $1;                

                #run 'format' then select the disk number then run 'inquiry' against it 
                #to display detailed information about the disk
                #(if you're not being too lazy check the man pages man for format options)
                #the $1 variable below would be the disk number, which is a 'back referrence'
                #of [(\d)] above.
                @b=`echo  '$1\ninq' |format -M -s 2>&1 `;
		
                #determine the disk name and store to a variable e.g.
                #2. c3t50060E8003A8F808d1 <HITACHI-OPEN-E*36-SUN-2106 cyl 65533 alt 2 hd 60 sec 260>
                #3. c3t50060E8003A8F808d2 <HITACHI-OPEN-E*3-SUN-2106 cyl 59275 alt 2 hd 15 sec 96>      
                #looking from above number 2 would have "HITACHI-OPEN-E*36-SUN-2106" as its disk name
                #and "HITACHI-OPEN-E*3-SUN-2106" for disk 3.
                 /.*\<(.*) cyl.*\>/;
                $n = $1;

                foreach (@b)
                {
                        if (/.*2114.*(\w{3})$/)
                        #this one is for HITACHI SAN luns having 2114 as their revision no.
                        #tries to match and parse this line for example:
                        #32 31 31 34 30 34 35 30 41 38 46 38 30 30 44 37     21140450A8F800D7
                        #the last 3 characters in the matching line above would be the lun id (0D7)
                        {
                                #print what was 'back referrenced' by perl [(\w{3}]
                                &printer;#call the printer() subroutine defined below
                        }
                        if (/.*3\.91(\w{3}).*/)
                        #this one's for IBM SANs that has 3.91 for their revision version
                        #tries to match and parse this line:
                        #33 2e 39 31 37 30 43 32 34 31 37 35 20 20 20 20     3.9170C24175
                        #the next 3 characters right after 3.91 would be the lun id
                        {
                                #print was was 'back referrenced' by perl [(\w{3})]
                                &printer;
                        }
                        if (/.*\&\.\M\.(\w{4})/)
                        #matches EMC SYMMETRIX with 5670 revision. parsing the LUN ID for this is
                        #a bit different because the ID is on a different line. It tries to match 
                        #a similar line below('&.M.' is the pattern that we're looking for):
                        #26 00 4d 00 30 31 42 45 00 00 00 00 00 00 00 00     &.M.01BE........
                        #the LUN ID above would then be "01BE"
			{
                                #print what was 'back referrenced' by perl [(\w{4})]
                                &printer;
                        }
                }
       }
}

sub printer
{
        #$m = disk number
        #$n = disk name
        #$b = lun id
        $b = $1;
        print "$m\t $n\t $b\t \n";
}


finally, documented and posted. I spent a hefty amount of time trying to hack css stuff just so it’ll look well with syntax highlighter. this one’s for you Suri ;)

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Security Code:

This site uses Akismet to reduce spam. Learn how your comment data is processed.