# Counter function problems...

**URL:** https://community.unix.com/t/counter-function-problems/186948
**Category:** Shell Programming and Scripting
**Created:** [February 26, 2008, 6:36pm UTC](https://community.unix.com/t/counter-function-problems/186948 "2008-02-26T18:36:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![LinuxRacr](https://community.unix.com/letter_avatar/linuxracr/32/5_5575768a8748004e209b776fc1b2916d.png) [@LinuxRacr](https://community.unix.com/u/LinuxRacr)
#### Post date: [February 26, 2008, 6:36pm UTC](https://community.unix.com/t/counter-function-problems/186948/1 "2008-02-26T18:36:25Z")

</div>

Ok, here is the issue I have..

I wrote a script that builds disk groups using vxvm, and it works really good. I added a feature that would tell you the max size you could build your your lvol to. I do this by getting the size of the disks I am using in KB, I subtract 5104 from it, and then I multiply it by the number of disks I am using to build my disk group. I set this to a variable called $NUMBER for use throughout the script. The function is finished, it outputs the answer to a file called value.txt. For some reason it works great until $NUMBER = 5 or more.

Below is the section of the script that is giving me issues:

```nohighlight
function adder_func
         {
         TYPE=$1
         if [-s sizes.$TYPE]; then
            let sum=0
            for i in `cat sizes.$TYPE`
            do
             ((i=$i - 5104))
             ((new_sum=$i + $sum))
             sum=$new_sum
            done
            ((last_sum=$new_sum*$NUMBER))
            echo ${last_sum}
           else
            break
          fi
         }

## Call the adder_func function and output to value.txt to get the max size for your lvol.
adder_func size > value.txt

```

When the function is with an option called 'size' it reads from a file called sizes.size (sizes.$TYPE). As you see, the size option is the same as the $TYPE variable.

Output from sizes.size (which is the size of the disks in KB):  
524288000

Here is the output from value.txt when the $NUMBER variable = 5:  
-1149269920

When I do the math, of course it shouldn't be a large negative number:

root@server:/root\_home\> bc -l  
524288000-5104  
524282896  
524282896\*5  
2621414480

So it should be 2621414480 or 2499.97GB, or about 2.5TB.

Am I surpassing the numerical limits of the function?

---

<div class="post-metadata">

### Author: ![LinuxRacr](https://community.unix.com/letter_avatar/linuxracr/32/5_5575768a8748004e209b776fc1b2916d.png) [@LinuxRacr](https://community.unix.com/u/LinuxRacr)
#### Post date: [February 26, 2008, 8:58pm UTC](https://community.unix.com/t/counter-function-problems/186948/2 "2008-02-26T20:58:32Z")

</div>

I fixed it by combining two functions into one:

```nohighlight
function adder_func
         {
         TYPE=$1
         if [-s sizes.$TYPE]; then
            let sum=0
            for i in `cat sizes.$TYPE`
            do
             ((i=$i-5104))
             ((new_sum=$i + $sum))
             sum=$new_sum
            done
            ((meg_sum=$new_sum/1024))
            ((gig_sum=$meg_sum/1024))
            ((last_sum=$gig_sum*$NUMBER))
            echo ${last_sum}G
           else
            break
          fi
         }

## Call the adder_func function and output to value.txt to get the max size for your lvol.
adder_func size > value.txt

```

Now everything will be GigaByte readable, instead of in KBytes.

And now the output of value.txt:  
2495G

And the effect:

Are you ready to create a lvol in fakedg?  
Enter 'y' for Yes or 'n' for No :y

Enter the name of your lvol.

Lvol name :fakelvol

Enter the size of your lvol.  
The maximum size is: 2495G

Lvol size :
