1752738 Members
5417 Online
108789 Solutions
New Discussion юеВ

Re: Script Errors

 
SOLVED
Go to solution
Sundar_7
Honored Contributor

Script Errors


I have a script written by someone else and I just would like a "second-eye" opinion from you folks.

The objective of the script is to test and confirm all the /stand volumes (Primary and Mirror) are referred in the BDRA of VG00.

I kinda figured out what is wrong with the script. There is one typo and one "logical" error in the AWK statement.

Before escalating this problem to the script's author, I just wanted to confirm. I dont want to embarrass myself :-).

Anyone who spots the errors will be awarded bunnies :-)

==============================================
BOOT_HEADER=/tmp/boot.$$
STAND_DEVS="/dev/dsk/c1t6d0 /dev/dsk/c2t6d0"
lvlnboot -v vg00 | sed 's/PV Name/PV_Name/g' > $BOOT_HEADER 2>/dev/null
STATUS=""
echo "Checking BOOT DISK definitions: \c"
for BOOTING_DEVICE in $STAND_DEVS
do
CHECK_COUNT=$(cat $BOOT_HEADER | grep "Boot Disk" | grep $BOOTING_DEVICE| wc -l)
case $CHECK_COUNT in
1) STATUS="OK";;
0) STATUS="ERROR - $BOOTING_DEVICE not defined.";;
*) STATUS="ERROR - multiple entries defined for $BOOTING_DEVICE"
esac
done
echo $STATUS
STATUS=""
echo "Checking BOOT LV(stand) definition: \c"
for STAND_DEVICE in $STAND_DEVS
do
CHECK_COUNT=$(cat $BOOT_HEADER | awk 'BEGIN {STAND_CHECK=0} { if ($1 == "PV_Name" || $1 == "Boot:") {STAND_CHECK=1} if ($1 == "Root:") {STAND_CHECK=0} if ((STAND_CHECK == 1) && (NF == 4)) {print $4} if ((ST
AND_CHECK == 1) && (NF == 1)) {print $1}}' | grep -c $STAND_DEVICE)
case $CHECK_COUNT in
1) STATUS="OK";;
0) STATUS="ERROR - $STAND_DEVICE not defined.";;
*) STATUS="ERROR - multiple entries defined for $STAND_DEVICE"
esac
done
echo $STATUS
==============================================
# ./script
Checking BOOT DISK definitions: OK
Checking BOOT LV(stand) definition: ERROR - /dev/dsk/c2t6d0 not defined.
#
# lvlnboot -v /dev/vg00
Boot Definitions for Volume Group /dev/vg00:
Physical Volumes belonging in Root Volume Group:
/dev/dsk/c1t6d0 (0/0/2/0.6.0) -- Boot Disk
/dev/dsk/c2t6d0 (0/0/2/1.6.0) -- Boot Disk
PV Name: lvol1 on: /dev/dsk/c1t6d0
/dev/dsk/c2t6d0
Root: lvol3 on: /dev/dsk/c1t6d0
/dev/dsk/c2t6d0
Swap: lvol2 on: /dev/dsk/c1t6d0
/dev/dsk/c2t6d0
Dump: lvol2 on: /dev/dsk/c1t6d0, 0

#
=============================================
Learn What to do ,How to do and more importantly When to do ?
6 REPLIES 6
Mike Stroyan
Honored Contributor
Solution

Re: Script Errors

The check for $1 == "PV_Name" should be
$1 == "PV_Name:"

The STATUS is overwritten every time through the loop, so only the STATUS from the last device is reported. The loop could report an error message immediately for each error. It could also set a flag to suppress a final "OK" message that would be printed after a successful loop.
Mike Stroyan
Honored Contributor

Re: Script Errors

The script also seems to be leaving the /tmp/boot.$$ file lying around. It should clean that up.
Sundar_7
Honored Contributor

Re: Script Errors

Mike,

You got the first one right on.

I do see one major problem with the awk statement

CHECK_COUNT=$(cat $BOOT_HEADER | awk 'BEGIN {STAND_CHECK=0} { if ($1 == "PV_Name" || $1 == "Boot:") {STAND_CHECK=1} if ($1 == "Root:") {STAND_CHECK=0} if ((STAND_CHECK == 1) && (NF == 4)) {print $4} if ((ST
AND_CHECK == 1) && (NF == 1)) {print $1}}' | grep -c $STAND_DEVICE)


Here, author is trying to print the device files linked as /stand in BDRA. AWK sets the STAND_CHECK to 1 when it sees "PV_Name" in $1, to 0 when it sees "Root:" and prints the device file ($4 and $1) whenever STAND_CHECK == 1.

I think the AWK statement should set STAND_CHECK to 0 when it sees anything other than "PV_Name" in $1. With the current code, STAND_CHECK will stand set to 1, even when it is parsing "Swap:" and "Dump:" ?? right ?

- Sundar
Learn What to do ,How to do and more importantly When to do ?
Mike Stroyan
Honored Contributor

Re: Script Errors

The intention is that the ($1 == "Root:") will always match the first line after the list of devices in the "PV_Name:" section. That seems like a reasonable assumption based on the sample data. Seeing "Root:" will turn off STAND_CHECK for the rest of the lines in the file.

The awk script will correctly accept an arbitrary number of lines that list one device file per line after a "PV_Name:" line. When reading the awk script remember that more than one of the 'if' lines can apply to a single line of input. The test for "PV_Name:" and "Boot:" turn on STAND_CHECK, which applies immediately to the (NF == 4) test on the same line of input.

Note that you can also see a line like this, which the awk script handles correctly-
Boot: lvol1 on: /dev/dsk/c0t3d0
Sundar_7
Honored Contributor

Re: Script Errors

Mike: - I understand how awk processes if sentense in the same line :-). What I missed out, was that STAND_CHECK remains set to 0, for rest of the lines.
Learn What to do ,How to do and more importantly When to do ?
Sundar_7
Honored Contributor

Re: Script Errors

See my above posts.
Learn What to do ,How to do and more importantly When to do ?