Pages

Find the rootvg Disk AIX Server

The script will do:
  • Collects all disks with sizes
  • Collects rootvg disks with sizes
  • Finds the target disk from rootvg list
  • Gets its size
  • Finds all disks with the same size
  • Outputs those disks
  • Finally, lists those disks info with lspv
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#!/bin/ksh

# Temp files
disk_size1=/tmp/disk_size1
disk_size2=/tmp/disk_size2

# Clear temp files if they exist
> "$disk_size1"
> "$disk_size2"

# Collect all disks sizes
for pv1 in $(lspv | awk '{print $1}')
do
  echo "Disk Size: $pv1 $(bootinfo -s $pv1)" >> "$disk_size1"
done

# Collect rootvg disks sizes
for pv2 in $(lspv | grep rootvg | awk '{print $1}')
do
  echo "Disk Size: $pv2 $(bootinfo -s $pv2)" >> "$disk_size2"
done

# Get the target disk from /tmp/disk_size2
target_disk=$(awk '{print $3; exit}' "$disk_size2")

if [ -z "$target_disk" ]; then
  echo "No target disk found in $disk_size2"
  exit 1
fi

# Get the size of the target disk from /tmp/disk_size1
target_size=$(awk -v disk="$target_disk" '$3 == disk {print $4}' "$disk_size1")

if [ -z "$target_size" ]; then
  echo "Disk $target_disk not found in $disk_size1"
  exit 1
fi

echo "Target disk: $target_disk"
echo "Target disk size: $target_size"
echo "-------------------------------------------------------------------------------------------------------------"
# Find all disks with the same size and save to /tmp/disk_size2 (overwrite)
awk -v size="$target_size" '$4 == size {print "Disk Size: " $3 " " $4}' "$disk_size1" > "$disk_size2"

echo "Root VG DISK are................................................................................................................."
cat "$disk_size2"

echo "-------------------------------------------------------------------------------------------------------------"
echo "Detailed lspv info for matching disks:"
for i in $(awk '{print $3}' "$disk_size2")
do
  lspv | grep "$i"
done
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1. Add the above script contents
# vi remove_dead_luns.ksh
2. Make it executable
# chmod +x remove_dead_luns.ksh
3. Run script
# ./remove_dead_luns.ksh
or
# sh remove_dead_luns.ksh

Script Output:
Target disk: hdisk2
Target disk size: 46080
Root VG DISK are.......................................
Disk Size: hdisk1 46080
Disk Size: hdisk2 46080
-------------------------------------------------------
Detailed lspv info for matching disks:
hdisk1         00c2d8d8c55583fa                    None
hdisk2         00c2d8d823db38fb                    rootvg          active

No comments:

Post a Comment