GotoDBA Infrastructure ASM Disks Scripts

ASM Disks Scripts

One of my customers is working with ASM and their database grows really fast. So every one in a while we need to add another ASM disk to the system.

Before I add a new ASM disk, I usually verify that there is indeed a new disk in the system that is not being used. And this includes multiple steps (to check disks and partitions allocated to filesystem and those allocated to ASM).
So, I’ve decided to write a script to do that. Here it is, feel free to use it and let me know if I missed anything. Here are two scripts, one prints all ASM disks with their devices and diskgroup, the other one scans the partitions (for linux, currently working only with asmlib, and only for standard partitions using fdisk) and prints what they are used for.
List physical device and ASM diskgroup for each ASM disk:


#!/bin/bash
ora_user=oracle
asm_sid=+ASM
padding=20
function get_dg() {
asm_disk=$1
su – ${ora_user} -c "
export ORACLE_SID=${asm_sid}
ORAENV_ASK=NO
. /usr/local/bin/oraenv -s
sqlplus -s / as sysasm <<- EOF
set pages 0 lines 100 feedback off
select name from v\\\$asm_diskgroup
where group_number=(select group_number from v\\\$asm_disk where path='ORCL:${asm_disk}');
exit
EOF
"
}
## main
if [ "$(whoami)" != "root" ]; then
echo "Please run this script as root"
exit
fi
echo
echo "List of ASM disks in the system"
echo "==============================="
echo
printf "%-${padding}s %-${padding}s %s\n" "ASM DISK" "Physical Device" "ASM Diskgroup"
printf "%-${padding}s %-${padding}s %s\n" "——–" "—————" "————-"
for asm_disk in $(oracleasm listdisks); do
p_disk=$(oracleasm querydisk -p ${asm_disk} | egrep '^/dev/' | cut -d ':' -f 1)
asm_dg=$(get_dg ${asm_disk})
printf "%-${padding}s %-${padding}s %s\n" ${asm_disk} ${p_disk} ${asm_dg}
done

view raw

list_asm.sh

hosted with ❤ by GitHub

List all disks and partitions with their usage:


#!/bin/bash
if [ $(whoami) != "root" ]; then
echo "Please run this script as root"
exit
fi
asm_disks=""
for asm_disk in $(oracleasm listdisks); do
asm_disks=$(echo -e "${asm_disks}\n${asm_disk} $(oracleasm querydisk -p ${asm_disk} | egrep '^/dev/' | cut -d ':' -f 1)")
done
disks=$(fdisk -l | egrep 'Disk /dev' | awk '{print $2}' | sed -e 's/://g')
for d in ${disks}; do
parts=$(fdisk -l ${d} | egrep '^/dev/' | cut -f 1 -d ' ')
if [ -z "${parts}" ]; then
# no partitions
fs=$(df -P | grep ${d} | awk '{print $6}')
if [ -n "${fs}" ]; then
# file system
echo "Device ${d} – filesystem: ${fs}"
else
# asm
asm=$(echo "${asm_disks}" | grep ${d} | awk '{print $1}')
if [ -n "${asm}" ]; then
echo "Device ${d} – ASM (${asm})"
else
echo "Device ${d} – unallocated"
fi
fi
else
echo "Device ${d}:"
for p in ${parts}; do
# check filesystem
fs=$(df -P | grep ${p} | awk '{print $6}')
if [ -n "${fs}" ]; then
# file system
echo " – Partition ${p} is filesystem: ${fs}"
else
# asm
asm=$(echo "${asm_disks}" | grep ${p} | awk '{print $1}')
if [ -n "${asm}" ]; then
echo " – Partition ${p} is ASM (${asm})"
else
echo " – Partition ${p} is unallocated"
fi
fi
done
fi
done

view raw

list_disks.sh

hosted with ❤ by GitHub

4 thoughts on “ASM Disks Scripts”

    1. Hi Prakash,
      The scripts are on the page, you can simply copy and paste them to a file and execute them.
      Liron

  1. Hi Liron,

    Getting below error while executing 1st script :

    List of ASM disks in the system
    ===============================

    ASM DISK Physical Device ASM Diskgroup
    ——– ————— ————-
    -bash: line 10: warning: here-document at line 4 delimited by end-of-file (wanted `EOF’)

    1. Hi Venkhatesh,
      This is strange as the line numbers don’t really make sense. Can you double check you copied the entire script?
      Liron

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post