- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Counter function problems...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2008 03:35 PM
тАО02-26-2008 03:35 PM
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:
-----------------------------------------------
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@werver:/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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2008 04:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2008 04:45 PM
тАО02-26-2008 04:45 PM
Re: Counter function problems...
---------------------------------------------
function adder_func2
{
TYPE=$1
if [ -s value.$TYPE ]; then
let sum=0
for i in `cat value.$TYPE`
do
((i=$i/1024))
((new_sum=$i + $sum))
sum=$new_sum
done
((gig_sum=$new_sum/1024))
echo ${gig_sum}G
else
break
fi
}
## Call the adder_func2 function and output to value2.txt to get the
## max size for your lvol in GB.
adder_func2 txt > value2.txt
---------------------------------------------
When the function is ran with an option called 'txt' it reads from a file called value.txt (value.$TYPE). As you see, the txt option is the same as the $TYPE variable.
Here is the output of value2.txt, which just took the value from value.txt (-1149269920) and divided it by 1024 twice:
-1096G
This is why I would do such a thing:
---------------------------------------------
VALUE=`cat value.txt`
VALUE2=`cat value2.txt`
echo "Enter the size of your lvol."
echo "The maximum size is: $VALUE or $VALUE2 "
echo
print -n "Lvol size :"
---------------------------------------------
This is the resulting output:
Enter the size of your lvol.
The maximum size is: -1149269920 or -1096G
I want to give the option of both KB or GB readable for size options, but it looks like it may be better to just scale to GB readable, and be done with it.
Perhaps I should combine the two.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2008 05:03 PM
тАО02-26-2008 05:03 PM
Re: Counter function problems...
---------------------------------------------
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
---------------------------------------------
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 :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2008 05:13 PM
тАО02-26-2008 05:13 PM
Re: Counter function problems...
As an aside:
# VALUE=`cat value.txt`
...is faster if you do (instead):
# VALUE=$(
Regards!
...JRF...
- Tags:
- evil cat