Thursday, June 27, 2013

Scripting LUN path count and device info

During a recent project I cut hundreds of LUNs to present to a few Solaris 10 servers. I wanted a way to check the total number of LUNs for each server, and that each LUN was properly dual pathed. To do this, I wrote the following shell script. It will list out the LUN device path and number of paths, comma seperated, and the total number of LUNs at the end.

Remember if you're running this on a machine which has hundreds of LUNs presented to it, you're best directing the output to a file to prevent the screen buffer refresh slowing down the return rate of your results.

#!/bin/ksh

a=0
print "Device_Path,Path_Count"

# probe for LUNS
luxadm probe|grep Logical|
while
     read CRAP DEV_PATH
do

     # increment LUN count
     let a+=1

     # print device path
     print -n "${DEV_PATH:##Path:},"

     # check we have dual paths on each LUN
     pathCount=`luxadm display ${DEV_PATH:##Path:}|grep State|wc -l|tr -d ' '`

     if [ $pathCount -lt 2 ]; then
          errorMessage=" - WARNING: LUN does not contain redundant path"
     fi

     # check for path status other than online
     offlinePath=`luxadm display ${DEV_PATH:##Path:}|grep State|grep -v ONLINE`

     if [ -z $offlinePath ]; then
          offlinePath=""
     else
           errorMessage="$errorMessage - WARNING: 1 or more paths detected as NOT ONLINE"
     fi

     # print number of paths and path error if an offline path was found
     print "$pathCount $errorMessage"

done

# print number of LUNS discovered
echo "$a LUNS presented."

2 comments: