Friday, 4 November 2016

Script to get disk details in Solaris [scanluns]

We can use the format command to view disk information & the prtvtoc command to list the partition map of the disks. Format is menu driven so if we need to check details for say 100 disks, it might take a while. Prtvtoc shows the space allocation in the form of sectors which again isn't exactly 'human readable'.

So, here is a script to get disk details in a very readable & convenient fashion.

#!/bin/bash
# script to scan the LUNS for HP 3Par storage in Solaris()
# @(#) v0.1 scanluns 
PATH=$PATH:/usr/bin:/usr/sbin
export PATH
echo | format > /tmp/format.out
for x in `cat /tmp/format.out | egrep "(3PAR|VIOLIN)" | grep -v available | awk '{print $2}'`
do
    Model=`luxadm display /dev/rdsk/${x}s2 | grep Vendor | awk '{print $2}'`
    Luns_size_MB=`luxadm display /dev/rdsk/${x}s2 | grep Unformatted | awk '{print $3}' | awk -F"." '{print $1}'`
    Luns_size_GB=`echo $Luns_size_MB/1024|bc`
    Luns_WWN=`echo $x | cut -c 4-35`
    Luns_Hex_ID=`luxadm display /dev/rdsk/${x}s2 | grep "Device Address" | awk -F"," '{print $2}' | sort -u`
    Luns_Hex_ID_Upper=`echo $Luns_Hex_ID | tr '[:lower:]' '[:upper:]'`
    Luns_Dec_ID=`echo "ibase=16; $Luns_Hex_ID_Upper"|bc`
    Operational_Path=`luxadm display /dev/rdsk/${x}s2 | grep State | grep ONLINE | wc -l`
    Failed_Path=`luxadm display /dev/rdsk/${x}s2 | grep State | grep OFFLINE | wc -l`
    #FP=`luxadm display /dev/rdsk/${x}s2 | grep Contr | awk '{print $2}' | sort -u | sed 's/^.\{8\}//' | tr ' ' '\n'`
    #FPINST=`grep $FP /etc/path_to_inst | grep '"fp"' | awk '{print $2}'`
    echo Disk: $x WWN Number: $Luns_WWN LUN ID: $Luns_Dec_ID Model: $Model  Size: $Luns_size_GB GB Working Paths: $Operational_Path Failed Paths: $Failed_Path
done


Just redirect the output of this script to a file & check for details of any disk by doing a grep for the required disk from the output file.

Here is a sample output:

grep c0t60002AC00000000000000BFA0000935Cd0 scanluns_out.03112016
Disk: c0t60002AC00000000000000BFA0000935Cd0 WWN Number: 60002AC00000000000000BFA0000935C LUN ID: 160 Model: 3PARdata Size: 1000 GB Working Paths: 16 Failed Paths: 0

Although this is specific for 3PAR disks but it can be tweaked for disks from other storage vendors as well.

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...