Hi,
I need to know who can I create an script in order to check server mirror in AIX. I got this script
!/usr/bin/ksh
#
# Check if a VG is mirrored.
#
# lsattr -El <lvname> -a strictness -a copies
# If copies=2 and scrictness=y, then VG is mirrored
#
# LVs are retrieved via 'lsvg -l <vg>|grep -v <vg>:|grep -v LPs|awk {'print $1'}
#
# Return codes:
#
# 0 VG is mirrored
# 1 Some LVs are not mirrored
# 2 All LVs in VG are not mirrored
# 3 No VG name(s) supplied
# 4 One or more invalid VG specified
# 5-? Other error found
#
if [ "$#" -eq "0" ] ; then
echo "Please specify one or more volume group names"
exit 3
fi
#
VGs=$@
for VG in $VGs ; do
RCforVG=0
if [ ! -e /dev/${VG} ] ; then
RCforVG=4
continue
fi
LVCount=0
MLVCount=0
for LV in getlvodm -L $VG | awk '{print $1}' ; do
LVCount=expr $LVCount + 1
Strict=lsattr -El $LV -a strictness|awk '{print $2}'
Copies=lsattr -El $LV -a copies|awk '{print $2}'
if [ "$Strict" = "y" -a "$Copies" -eq "2" ] ; then
MLVCount=expr $MLVCount + 1
else
:
fi
if [ "$MLVCount" -eq "0" ] ; then
RCforVG=2
fi
if [ "$MLVCount" -gt "0" -a "$MLVCount" -ne "$LVCount" ] ; then
RCforVG=1
fi
done
echo "Result code for $VG: $RCforVG"
done
This do not work �can someone give me a hand on this?
In which way it "doesn't work"? Could you be bit more specific, please? Are there error codes, error messages, wrong results (if yes, which ones?), etc.?
Two errors i can tell you from a glance:
Strict=lsattr -El $LV -a strictness|awk '{print $2}'
Copies=lsattr -El $LV -a copies|awk '{print $2}'
This can't work. You need a subshell for this.
Strict="$(lsattr -El $LV -a strictness|awk '{print $2}')"
Copies=$(lsattr -El $LV -a copies|awk '{print $2}')
And this is not wrong, but problematic:
if [ "$Strict" = "y" -a "$Copies" -eq "2" ] ; then
It is possible to mirror LVs not only once (two copies) but also twice (three copies). Further, you do not want to use double quotes when you do integer comparisons. You might want to change this line to
if [ "$Strict" = "y" -a $Copies -ge 2 ] ; then
I hope this helps.
bakunin
thanks for your healp when I try to execute the script the following error acccur
./discos.sh rootvg
./disk.sh[25]: 0403-057 Syntax error at line 33 : `|' is not expected.
Here is line 33:
for LV in getlvodm -L $VG | awk '{print $1}' ; do
Yes, this won't work and for the same reason the other two lines won't work: you need a subshell for this:
for LV in $(getlvodm -L $VG | awk '{print $1}') ; do
But even if you'd write it syntactically correct you should not do it this way anyways and there are a lot of obvious misconceptions about the workings of LVM in the script. I don't have the time right now to expand on this, but will do so once i get back in a few hours, so stay tuned.
I hope this helps.
bakunin
I will provide the "start command", someone else can provide the parsing bit.
Note: I am not mirrored.
What to look for!
There are two columns labeled LP and PP. Here is can determine how many copies there are. If PP == LP, one copy; if PP is double LP - 2 copies, if PP is three times LP - then three copies of the data (not copies of the first copy, copies is the number of copies of data - 1, 2 or 3).
The magic command to start this is:
lsvg -o | lsvg -il
Sorry, it took me a while longer than i thought to come back to here:
if [ ! -e /dev/${VG} ] ; then
you look for an existing device file as a test if the VG is online. You should use the AIX methods instead, because they always work, while this may or may not work. Use
lsvg -o
to get a list of online VGs. Change your test accordingly. Then
for LV in getlvodm -L $VG | awk '{print $1}'
Even if this would be syntactically correct (which it isn't, see posts above) it would be better to use normal AIX methods to get a list of LVs in a VG. Use
lsvg -l <vgname>
to create such a list.
I hope this helps.
bakunin