Please correct the code

Hi,

Some part of output:

$ hwmgr show scsi
SCSI DEVICE DEVICE DRIVER NUM DEVICE FIRST
HWID: DEVICEID HOSTNAME TYPE SUBTYPE OWNER PATH FILE VALID PATH
-------------------------------------------------------------------------
68: 0 mullins disk none 0 1 dsk0 [0/0/0]
69: 1 mullins disk none 0 1 dsk1 [0/1/0]
71: 4 mullins disk none 0 4 scp0 [2/0/0]
72: 5 mullins disk none 2 4 dsk2 [2/0/3]
73: 6 mullins disk none 2 4 dsk3 [2/0/4]
74: 7 mullins disk none 2 4 dsk4 [2/0/6]
75: 8 mullins disk none 2 4 dsk5 [2/0/7]
76: 9 mullins disk none 2 4 dsk6 [2/0/8]
77: 10 mullins disk none 0 4 dsk7 [2/0/9]
78: 11 mullins disk none 0 4 dsk8 [2/0/10]
79: 12 mullins disk none 0 4 dsk9 [2/0/11]
80: 13 mullins disk none 0 4 dsk10 [2/0/12]

Main intention of doing this is to meet BID value=35 by using required number of disks.
a[x]=x (unknown value to programmer)varies from machine to machine.
And a[x] value can be found from below code ..
hwmgr show scsi > scsi.tmp
while read line; do
a[x]=`echo $line | grep "dsk" | awk '{ print $7 }'`
Coming to BID concept:
--------------------------------
BID value =(No of partitions * NUM PATH value).
In general each disk has 4 partitions (a,b,g,h) and and for each partition(a,b,g,h) their wll be NUM PATH value.Each partition NUM PATH value will be equal to NUM PATH value of that particular disk.
Example:- Suppose dsk1 has NUM PATH=4 then partition "a" has Total number of paths=4 partition "b" total number of paths=4 Partition "g" total number of paths=4 partition "h" total number of paths=4 Hence,if you use dsk1 then we can have BID value=(No of partitions * NUM PATH)=4*4=16.

So our requirement is to meet BID value=35.
After getting NUM PATH value by above code,we must use the required number of disks to meet BID=35.
Example:Let say dsk2 and dsk3 has NUMPATH=4 then we can get BID value=16+16=32) Still we didnt meet BID=35 and here we must note that we can't use the disk which has NUM PATH=4 now at this stage because 32+4=36 (not equal to 35) so we must use less than NUM PATH=4 , say if you find NUM PATH=1(less than NUM PATH=4)so we can proceede and here we must check how many partitions to be used to meet BID value=35.In this case only 3 partitions are required which has NUM PATH=1 so finally
32+3=35..

I wrote the below code as per my above information..
#!/bin/ksh
main() {
set -x
int a[10],b[10];
# array a and b are used to store the paths and partitions for the disks until we get the
proper BID Value
int x = 0,y = 0, BID = 0;
int count=0,t=0;
while [[ $BID -le 35 ]] ; do
x=`expr $x + 1`;
hwmgr show scsi > scsi.tmp
while read line; do
a[x]=`echo $line | grep "dsk" | awk '{ print $7 }'`
done < scsi.tmp
b[x]=4;
BID+=a[x].b[x];
echo $BID;
if [[ $BID -gt 35 ]]; then
y = $BID - 35;
echo $y;
BID-= a[x].b[x];
if [[ count -eq 0 ]]; then
for i in b[x] ; do
t = a[x].i;
if [[ $y -eq $t ]] ; then
b[x] -= i;
BID += a[x].b[x];
count = 0;
break;
fi
count=1;
done
else
if [[ $count -eq 1 ]] ; then
a[x]=0;
b[x]=0;
fi
fi
else
if [[ $BID -eq 35 ]] ; then
break;
fi
fi
done
return;
}

Could you check it and correct me if you have better idea..
Request you to please provide inputs for this...

Use codetags -- the # on the icon bar -- once you highlight your script. This will maintain all the indenting and formatting of your program. Otherwise, it is very difficult to read.

Hi,

Please let me know how to " Use codetags -- the # on the icon bar -- as soon as the script starts..

Thanks,
Mansa

Paste your script into the message area.
Highlight your script
Press the # icon to apply CODE tags

This will maintain - what I hope - is a better formatted script.
It is very difficult to follow a script that is not indented at if's and loops.

Hi,

Some part of output:

$ hwmgr show scsi
SCSI DEVICE DEVICE DRIVER NUM DEVICE FIRST
HWID: DEVICEID HOSTNAME TYPE SUBTYPE OWNER PATH FILE VALID PATH
-------------------------------------------------------------------------
68: 0 mullins disk none 0 1 dsk0 [0/0/0]
69: 1 mullins disk none 0 1 dsk1 [0/1/0]
71: 4 mullins disk none 0 4 scp0 [2/0/0]
72: 5 mullins disk none 2 4 dsk2 [2/0/3]
73: 6 mullins disk none 2 4 dsk3 [2/0/4]
74: 7 mullins disk none 2 4 dsk4 [2/0/6]
75: 8 mullins disk none 2 4 dsk5 [2/0/7]
76: 9 mullins disk none 2 4 dsk6 [2/0/8]
77: 10 mullins disk none 0 4 dsk7 [2/0/9]
78: 11 mullins disk none 0 4 dsk8 [2/0/10]
79: 12 mullins disk none 0 4 dsk9 [2/0/11]
80: 13 mullins disk none 0 4 dsk10 [2/0/12]

Main intention of doing this is to meet BID value=35 by using required number of disks.
a[x]=x (unknown value to programmer)varies from machine to machine.
And a[x] value can be found from below code ..
hwmgr show scsi > scsi.tmp
while read line; do
a[x]=`echo $line | grep "dsk" | awk '{ print $7 }'`
Coming to BID concept:
--------------------------------
BID value =(No of partitions * NUM PATH value).
In general each disk has 4 partitions (a,b,g,h) and and for each partition(a,b,g,h) their wll be NUM PATH value.Each partition NUM PATH value will be equal to NUM PATH value of that particular disk.
Example:- Suppose dsk1 has NUM PATH=4 then partition "a" has Total number of paths=4 partition "b" total number of paths=4 Partition "g" total number of paths=4 partition "h" total number of paths=4 Hence,if you use dsk1 then we can have BID value=(No of partitions * NUM PATH)=4*4=16.

So our requirement is to meet BID value=35.
After getting NUM PATH value by above code,we must use the required number of disks to meet BID=35.
Example:Let say dsk2 and dsk3 has NUMPATH=4 then we can get BID value=16+16=32) Still we didnt meet BID=35 and here we must note that we can't use the disk which has NUM PATH=4 now at this stage because 32+4=36 (not equal to 35) so we must use less than NUM PATH=4 , say if you find NUM PATH=1(less than NUM PATH=4)so we can proceede and here we must check how many partitions to be used to meet BID value=35.In this case only 3 partitions are required which has NUM PATH=1 so finally
32+3=35..

I wrote the below code as per my above information..

#!/bin/ksh
main() {
set -x
int a[10],b[10];
# array a and b are used to store the paths and partitions for the disks until we get the 
proper BID Value
int x = 0,y = 0, BID = 0;
int count=0,t=0;
while [[ $BID -le 35 ]] ; do
x=`expr $x + 1`;
hwmgr show scsi > scsi.tmp
while read line; do
a[x]=`echo $line | grep "dsk" | awk '{ print $7 }'`
done < scsi.tmp
b[x]=4;
BID+=a[x].b[x];
echo $BID;
if [[ $BID -gt 35 ]]; then
y = $BID - 35;
echo $y;
BID-= a[x].b[x];
if [[ count -eq 0 ]]; then
for i in b[x] ; do
t = a[x].i;
if [[ $y -eq $t ]] ; then
b[x] -= i;
BID += a[x].b[x];
count = 0;
break;
fi
count=1;
done
else
if [[ $count -eq 1 ]] ; then
a[x]=0;
b[x]=0;
fi
fi
else
if [[ $BID -eq 35 ]] ; then
break;
fi
fi
done
return;
}

Could you check it and correct me if you have better idea..
Request you to please provide inputs for this...

Hi,

As per your suggestions,i modified in my previous update..
Please let me know incase if you need further modification..

Thanks,
Mansa.

So, there is no formatting of the script...
bummer... and tough to read.

Can you reformat, and add a few comments throughout to help understand what you are doing at the various steps?

Hi,

I pasted the entire information in message area and then selected code with mouse button and then clicked on # prompt.

But still the format hasnt changed...

Or else if that is possible with you,could you please change it if you dont mind..

Thanks in Advance,
Mansa

Is it indented (formatted) when you pasted it in?
I cannot easily format your code for you.

For instance, the following is something I just worked on for someone else. Note that there is formatting, which makes it much easier to read.

> cat play_file14 

cat -n file14 >file14n
for (( i=2; $i <= 4; i++ ))
  do 
  read cnt line
  if [ $i -eq $cnt ]
    then
    echo $line
  fi
done <file14n

Hi,

Now i did manually by changing each code of line one by one.. Could you please check it now..

Hi,

Some part of output:

$ hwmgr show scsi
SCSI DEVICE DEVICE DRIVER NUM DEVICE FIRST
HWID: DEVICEID HOSTNAME TYPE SUBTYPE OWNER PATH FILE VALID PATH
-------------------------------------------------------------------------
68: 0 mullins disk none 0 1 dsk0 [0/0/0]
69: 1 mullins disk none 0 1 dsk1 [0/1/0]
71: 4 mullins disk none 0 4 scp0 [2/0/0]
72: 5 mullins disk none 2 4 dsk2 [2/0/3]
73: 6 mullins disk none 2 4 dsk3 [2/0/4]
74: 7 mullins disk none 2 4 dsk4 [2/0/6]
75: 8 mullins disk none 2 4 dsk5 [2/0/7]
76: 9 mullins disk none 2 4 dsk6 [2/0/8]
77: 10 mullins disk none 0 4 dsk7 [2/0/9]
78: 11 mullins disk none 0 4 dsk8 [2/0/10]
79: 12 mullins disk none 0 4 dsk9 [2/0/11]
80: 13 mullins disk none 0 4 dsk10 [2/0/12]

Main intention of doing this is to meet BID value=35 by using required number of disks.
a[x]=x (unknown value to programmer)varies from machine to machine.
And a[x] value can be found from below code ..
hwmgr show scsi > scsi.tmp
while read line; do
a[x]=`echo $line | grep "dsk" | awk '{ print $7 }'`
Coming to BID concept:
--------------------------------
BID value =(No of partitions * NUM PATH value).
In general each disk has 4 partitions (a,b,g,h) and and for each partition(a,b,g,h) their wll be NUM PATH value.Each partition NUM PATH value will be equal to NUM PATH value of that particular disk.
Example:- Suppose dsk1 has NUM PATH=4 then partition "a" has Total number of paths=4 partition "b" total number of paths=4 Partition "g" total number of paths=4 partition "h" total number of paths=4 Hence,if you use dsk1 then we can have BID value=(No of partitions * NUM PATH)=4*4=16.

So our requirement is to meet BID value=35.
After getting NUM PATH value by above code,we must use the required number of disks to meet BID=35.
Example:Let say dsk2 and dsk3 has NUMPATH=4 then we can get BID value=16+16=32) Still we didnt meet BID=35 and here we must note that we can't use the disk which has NUM PATH=4 now at this stage because 32+4=36 (not equal to 35) so we must use less than NUM PATH=4 , say if you find NUM PATH=1(less than NUM PATH=4)so we can proceede and here we must check how many partitions to be used to meet BID value=35.In this case only 3 partitions are required which has NUM PATH=1 so finally
32+3=35..

I wrote the below code as per my above information..

#!/bin/ksh
main() {
set -x
int a[10],b[10];
# array a and b are used to store the paths and partitions for the disks until we get the 
proper BID Value
int x = 0,y = 0, BID = 0;
int count=0,t=0;
while [[ $BID -le 35 ]] ; do
   x=`expr $x + 1`;
   hwmgr show scsi > scsi.tmp
          while read line; do
              a[x]=`echo $line | grep "dsk" | awk '{ print $7 }'`
          done < scsi.tmp
b[x]=4;
BID+=a[x].b[x];
echo $BID;
          if [[ $BID -gt 35 ]]; then
              y = $BID - 35;
              echo $y;
              BID-= a[x].b[x];
                      if [[ count -eq 0 ]]; then
                                 for i in b[x] ; do
                                        t = a[x].i;
                                        if [[ $y -eq $t ]] ; then
                                              b[x] -= i;
                                              BID += a[x].b[x];
                                              count = 0;
                                              break;
                                        fi
                                        count=1;
                                  done
                       elif [[ $count -eq 1 ]] ; then
                           a[x]=0;
                           b[x]=0;
                       fi
                       
             elif [[ $BID -eq 35 ]] ; then
                   break;
             fi
done
return;
}

Could you check it and correct me if you have better idea..
Request you to please provide inputs for this...

First off, the following possible modification:

#   hwmgr show scsi > scsi.tmp
   grep "dsk" <scsi.tmp >scsi.dsk
          while read line; do
              a[x]=`echo $line | awk '{ print $7 }'`
              echo $line | awk '{ print $7 }'
          done < scsi.dsk

just do that grep once (perhaps even as part of the hwmgr command)

Unsure of you logic - what you are trying to do. It seems that you are trying to gigure out how to add up multiples of four and multiples of one to make 35. Then still, unclear on your goal.

Finally, your asked to check and correct. Well, is there something wrong with the code or the results? Or, are you just tryign to see if a better way?