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, Installation, NIM↑ Creating an LPP source and SPOT in NIM
Viewed 14108 times since Fri, Apr 19, 2019
AIX, Networking↑ Adding and deleting a static network route using the command line
Viewed 2372 times since Fri, Apr 19, 2019
AIX - How to get CPU infomation
Viewed 5010 times since Fri, Jun 8, 2018
AIX www web Links
Viewed 3073 times since Fri, Apr 19, 2019
AIX Creating a Volume Group
Viewed 2287 times since Tue, Jul 17, 2018
IVM and VLAN Tagging
Viewed 10061 times since Mon, May 28, 2018
Mirroring session (TTY) on AIX using portmir
Viewed 9003 times since Thu, Feb 21, 2019
AIX, System Admin Configuring dsh DSH
Viewed 3647 times since Fri, Apr 19, 2019
IBM AIX MPIO: Best practices and considerations
Viewed 10652 times since Wed, May 30, 2018
Using expect to automate mundane tasks
Viewed 1628 times since Mon, Jun 3, 2019