1831496 Members
3450 Online
110025 Solutions
New Discussion

for loop

 
j.bobby
Frequent Advisor

for loop

Hi all,

Can anybody tell me that how can i use "for" loop in finding out the stale physical extends in all mirrored logical volumes.
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: for loop

First you need a list of all of your mirrored LVs. This is a simple text file you could create with vi.

Something like:

# cat mirrored_lvs
/dev/vg00/lvol1
/dev/vg00/lvol2
/dev/vg00/lvol3
/dev/vg01/oralv1
/dev/vg02/oralv2

Now your for loop:

for LV in $(< mirrored_lvs)
do
echo ${LV}
lvdisplay -v ${LV} | grep stale
done

That is the simplest form of the script. More elaborate things could be done with dynamically building the list of LVs and checking for a count of stale extents, etc.
Doug O'Leary
Honored Contributor

Re: for loop

Hey;


vgdisplay -v vg00 | grep -i 'lv name' | awk '{print $NF}' | \
while read lv
do
stale=$(lvdisplay -v ${lv} | sed -n -e '/Logical extents/,$p' | \
grep stale | wc -l)
printf "%-20s %3d\n" ${lv} ${stale}
done
/dev/vg00/lvol1 0
/dev/vg00/lvol2 0
/dev/vg00/lvol3 0
/dev/vg00/lvol4 0
/dev/vg00/lvol5 0
/dev/vg00/lvol6 0
/dev/vg00/lvol7 0
/dev/vg00/lvol8 0
/dev/vg00/crash 0
/dev/vg00/usrsap 0
/dev/vg00/dazel 0
/dev/vg00/oracle 0
/dev/vg00/swap 0
/dev/vg00/swap1 0

If you want to do all vgs on the system, just remove the vg00 fro the top line of the inline script.

Doug O'Leary

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
James R. Ferguson
Acclaimed Contributor

Re: for loop

Hi:

How about:

# vgdisplay -v|awk '/LV Name/ {print $3}'|while read LINE;do echo ${LINE};lvdisplay -v ${LINE}|grep stale;done

The name of each logical volume will be listed unconditionally with any stale extents lists beneath.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: for loop

Here's another version that builds the list of LV's dynamically. It then checks to see if the "Mirror Copies" is greater than 0. If it is not the script does nothing. If it is it checks for the number of stale extents. If number of stale extents is 0, it prints that. If it is greater than 0, it prints that and the does an 'lvdisplay -v ${LV} | grep stale' to show you which extents are stale.

Feel free to modify as you see fit. While not necessarily a FOR loop, it does close to the same thing.

Doug's script above was the base/inspiration for this one.

#!/usr/bin/sh

typeset -i MIRROR
typeset -i NUMSTALE

vgdisplay -v 2>/dev/null | awk '/LV Name/ {print $3}' | \
while read LV
do
MIRROR=$(lvdisplay ${LV} | awk '/Mirror copies/ {print $3}')
if (( ${MIRROR} > 0 )) ; then
NUMSTALE=$(lvdisplay -v ${LV} |grep stale | wc -l)
echo "${LV} has ${NUMSTALE} stale extents"
if (( ${NUMSTALE} > 0 )) ; then
lvdisplay -v ${LV} | grep stale
fi
else
echo "${LV} is not mirrored"
fi
done