List STALE partitions across Volume Groups for each Logical Volume in AIX

List STALE partitions across Volume Groups for each Logical Volume in AIX

I wrote a tiny script that can report the number of stale partitions across multiple Volume Groups. If invoked with the -a flag the script will list LPs, PPs and Stale partitions for all Logical Volumes in all active Volume Groups. Using the -v flag only information for the specified Volume Group will be displayed.

Usage:

stale.sh -v rootvg
stale.sh -a

Sample output:

VG: rootvg   LV: hd5     LPs: 1      PPs: 2         STALE 0
VG: rootvg   LV: hd4     LPs: 6      PPs: 12        STALE 0
VG: rootvg   LV: hd2     LPs: 29     PPs: 58        STALE 0
VG: rootvg   LV: hd3     LPs: 4      PPs: 8         STALE 0
VG: rootvg   LV: hd1     LPs: 2      PPs: 4         STALE 0


The script is here:

#!/bin/ksh
#
# OS: AIX
# stale.sh
# Created by: aixdoc.wordpress.com
# THERE IS NO WARRANTY FOR THIS SCTIPT
############################################################################################
# This script if invoked with the -a flag will print for all Logical Volumes in all active #
# Volume Groups the number of LPs, PPs and stale partitions for each Logical Volume.       #
# Using the flag -v [ VG Name ] only information for the specified Volume Group will be    #
# displayed.										   #
############################################################################################
# Sample output: 									   #
# ...										           #
# VG: rootvg           LV: hd6           LPs: 16         PPs: 32        STALE 0            #
# VG: rootvg           LV: hd8           LPs: 1          PPs: 2         STALE 0            #
# VG: rootvg           LV: hd5           LPs: 1          PPs: 2         STALE 0            #
# VG: rootvg           LV: hd4           LPs: 6          PPs: 12        STALE 0            #
# VG: rootvg           LV: hd2           LPs: 29         PPs: 58        STALE 0            #
# ...											   #
############################################################################################ 

# Check if we run on AIX

if [[ `uname -s` != AIX  ]]
then print 'This script is designed for AIX only'
exit 1
fi

# Check if tmp file exists, if yes delete the file.

if [[ -a  /tmp/lslv_stale.out ]]
  then
	rm /tmp/lslv_stale.out
fi

# If no command line argument is specified, print usage

if [[ $# -eq 0 ]]; then
 print 'Usage: stale.sh [-a] List all LVs in all open VGs [-v VG_Name] List LVs in the specified VG'
  exit
fi

# If the -a flag is specified, get the list of all LVs from all active VGs. 

while [[ $1 = -* ]]; do
 case $1 in
	-a )

for vg in `lsvg -o`
 do
   lsvg -l $vg | awk 'NR>2 { print $1 }' >> /tmp/lslv_stale.out
     done

# Now run lslv against each Logical Volume and format the output as required.

for list_lv in `cat /tmp/lslv_stale.out`
  do
    lslv $list_lv |  awk -vORS=' ' 'NR==1 { printf "%-20s %-40s", "VG: " $6, "LV: " $3 } NR==7 {  printf "%-15s %-15s", "LPs: " $2, "PPs: " $4} NR==8 { printf "%-5s %-5s\n",  $1, $3 }'
            done;;

# Using the -v flag report only information for the specified VG
	-v )

lsvg -l $2 | awk 'NR>2 { print $1 }' >> /tmp/lslv_stale.out
for list_lv in `cat /tmp/lslv_stale.out`
  do
    lslv $list_lv |  awk -vORS=' ' 'NR==1 { printf "%-20s %-40s", "VG: " $6, "LV: " $3 } NR==7 {  printf "%-15s %-15s", "LPs: " $2, "PPs: " $4} NR==8 { printf "%-5s %-5s\n",  $1, $3 }'
	done;;

         *) print 'Usage: stale.sh [-a] List all LVs in all open VGs [-v VG_Name] List LVs in the specified VG'
return 1
esac
shift
done

# Delete temporary file

rm /tmp/lslv_stale.out
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
AIX www web Links
Viewed 2984 times since Fri, Apr 19, 2019
Authenticate AIX using MS DC’s kerberos servers (Active Directory)
Viewed 1939 times since Thu, Feb 21, 2019
Install and configure GNU watch (gwatch) on AIX
Viewed 7478 times since Thu, Feb 21, 2019
LVM: Unmirror/Mirror "rootvg" Volume Group
Viewed 3072 times since Mon, May 21, 2018
Control Your Logs AIX
Viewed 18558 times since Wed, May 30, 2018
LVM: Shrink & extend a filesystem/volume
Viewed 1890 times since Sun, Jun 3, 2018
Part 1, Network overview - Monitoring the hardware
Viewed 5118 times since Mon, Jun 4, 2018
How To Mirror VG and Root VG
Viewed 2765 times since Mon, May 21, 2018
Problem on resizing volume group on AIX 0516-1714, 0516-792, 0516-787, and 0516-404
Viewed 2236 times since Fri, Jul 6, 2018
How do I analyze and debug core files on AIX
Viewed 5577 times since Thu, Feb 21, 2019