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.


print "Device_Path,Path_Count"

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

     # 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"

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

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

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


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