Tanti Technology

My photo
Bangalore, karnataka, India
Multi-platform UNIX systems consultant and administrator in mutualized and virtualized environments I have 4.5+ years experience in AIX system Administration field. This site will be helpful for system administrator in their day to day activities.Your comments on posts are welcome.This blog is all about IBM AIX Unix flavour. This blog will be used by System admins who will be using AIX in their work life. It can also be used for those newbies who want to get certifications in AIX Administration. This blog will be updated frequently to help the system admins and other new learners. DISCLAIMER: Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility. If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.

Saturday 22 February 2014

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

No comments:

Post a Comment