Script: Get Device from Label in ASMLIB

WE can:

# /etc/init.d/oracleasm querydisk /dev/sdc5

Disk "/dev/sdc5" is marked an ASM disk with the label "VOL1"

But no idea, when use label to find device...: 

# /etc/init.d/oracleasm querydisk VOL1

Disk "VOL1" is a valid ASM disk on device [8, 37]

On asmlib support  since 2.1.0

# /etc/init.d/oracleasm querydisk -d VOL1

Disk "VOL1" is a valid ASM disk on device [8, 37]

So:

# ls -l /dev/* | grep 8, | grep 37

brw-rw----  1 root disk   8,  37 Jul 31 17:48 /dev/sdc5

that can help... then

Script: getasmlib 

---------------- Start File ----------------

#!/bin/sh

# Script: getasmlib Version 0.11

# by Surachart Opun

# http://surachartopun.com

if [ $# -ne 1 ]

then

  echo "Please Check arguments."

  echo

  echo "./getasmlib [label]"

  echo

  echo "        ./getasmlib VOL01"

  exit 0

fi

LABEL=$1

C=`/etc/init.d/oracleasm querydisk -d ${LABEL} |grep 'a valid ASM disk' |wc -l`

if [ ${C} -eq 0 ]

then

        echo "Don't Found ${LABEL} Disk in ASMLIB"

        exit 0

fi

M=`/etc/init.d/oracleasm querydisk -d ${LABEL} | grep 'a valid ASM disk' |awk -F\[ '{print $2 }'  | awk  '{print $1}'`

N=`/etc/init.d/oracleasm querydisk -d ${LABEL} | grep 'a valid ASM disk' |awk -F\, '{print $2 }'  | awk  -F\] '{print $1}'`

for x in ` ls -l  --time-style=long-iso /dev/* | grep ${M} | grep  ${N}' ' | awk '{print $9}' `

do

/etc/init.d/oracleasm  querydisk $x |grep -i ${LABEL}

done

---------------- End File ----------------

Example:

# ./getasmlib VOL1

Disk "/dev/sdc5" is marked an ASM disk with the label "VOL1"

# ./getasmlib VOL2

Disk "/dev/sdc6" is marked an ASM disk with the label "VOL2"

by Surachart Opun