Page 1 of 1

AIX script to list 3Par hdisks/LUN #/Volume Group

Posted: Thu Dec 10, 2009 11:06 am
by Richard Siemers
We wanted an easy way to list the 3Par luns on AIX and see what they were assigned to, specifically which volume group or if they were raw disks in Oracle ASM. We provision multiple tiers of storage to database hosts. FC 15k disks are used for the database drives, and SATA is used for the flash recovery area (backup to disk). Communication between storage admin and AIX admin can get confusing when trying to identify which luns are the SATA for backups.

Our local AIX team wrote these scripts to make this task easier. Root not required. You should have your AIX admin evaluate these scripts before you install and run them on their systems.

The first script is a modified lspv that lists all physical disks and displays which VG they are assigned to or if they belong to Oracle ASM.

lspv2

Code: Select all

#!/bin/ksh
if [ $# -eq 0 ]
then
        touch /tmp/ASM_lspv.out
        /usr/sbin/lspv > /tmp/lspv.out
        for i in `grep None /tmp/lspv.out | awk '{print $1}'`
        do
                ls -l /dev/r${i} | grep oracle > /dev/null 2>&1
                if [ $? -eq 0 ]
                then
                        echo "$i" >> /tmp/ASM_lspv.out
                fi
        done
        cat /tmp/lspv.out | grep -vwf /tmp/ASM_lspv.out > /tmp/lspv1.out 2>/dev/
null
        cat /tmp/lspv.out | grep -wf /tmp/ASM_lspv.out | sed 's/none
                    None/ASM Disk For Oracle                 ASM Disk        act
ive/' > /tmp/lspv2.out 2>/dev/null

        cat /tmp/lspv1.out /tmp/lspv2.out
        rm -f /tmp/ASM_lspv.out
        rm -f /tmp/lspv.out
        rm -f /tmp/lspv1.out
        rm -f /tmp/lspv2.out
else
        /usr/sbin/lspv $*
fi


The second script depends on the first script, and builds a list of just 3par disks, LUN ID, and VG assignment.

ls3par

Code: Select all

echo "Disk\tLUN\tVG Name"
for i in `lsdev -Cc disk | grep -i 3par | awk '{print $1}'`
do
LUNID=`lsattr -El $i | grep -i lun | awk '{print $2}' | awk -F"x" '{print $2}' |
 awk -F"000000000000$" '{print $1}'`
((mydec=16#$LUNID))
VGNM=`/opt/local/bin/lspv2 | grep -w $i | awk '{print $3}' | sed 's/Disk/ASM Dis
k/g'`
echo "$i\t$mydec\t$VGNM"  >> /tmp/3par.$$
done
cat /tmp/3par.$$ | sort -n +1 2>/dev/null
rm -f /tmp/3par.$$



Example Output wrote:Disk LUN VG Name
hdisk23 0 backupsvg
hdisk24 1 backupsvg
hdisk25 2 backupsvg
hdisk26 3 backupsvg
hdisk27 4 backupsvg
hdisk28 5 backupsvg
hdisk29 6 ASM Disk
hdisk30 7 ASM Disk
hdisk31 8 ASM Disk
hdisk32 9 ASM Disk
hdisk33 10 ASM Disk
hdisk42 11 hrdvora1vg
hdisk43 12 hrdvora3vg
hdisk44 13 hrdvora2vg
hdisk45 14 hrdvp1vg

Re: AIX script to list 3Par hdisks/LUN #/Volume Group

Posted: Fri Aug 20, 2010 12:01 pm
by ahalsell
I like this.

When I implement this, I will make a small change to add some randomness to the filenames that get the redirects in /tmp

rnd=$RANDOM # generate a random number and assign it to a variable
touch /tmp/ASM_lspv.${rnd}.out
/usr/sbin/lspv > /tmp/lspv.${rnd}.out

etc...


That will prevent an unprivileged user from doing:

ln -s /etc/passwd /tmp/lspv.out


I'd hate to have to clean up the mess after effectively:

lspv > /etc/passwd

:mrgreen:

Re: AIX script to list 3Par hdisks/LUN #/Volume Group

Posted: Wed Nov 12, 2014 6:31 pm
by rmkenyon
You can also use HP 3PARinfo on AIX (and HPUX, Solaris, Linux, VMware & Windows) to get this info without resorting to script writing. It's a lightweight tool installed into the OS.

Very handy for giving a common understanding of LUN info if there are separate OS/Application Admins and Storage/SAN Admins who sometimes might talk at cross-purposes.

Download for FREE from HP's software depot: https://h20392.www2.hp.com/portal/swdep ... r=3PARinfo

Latest version is now 1.3. See release notes and user guide for more info on installation, command syntax, etc.