[SLUG] Shell math/BASH question

2010-10-18 Thread DaZZa
Learned denizens $POE runs a system which is extensively Linux, and part of the system is a small script which monitors the free space various devices using some third party software. The software isn't the issue - doing the math to work out the percentage free is. We're inth e middle of

Re: [SLUG] Shell math/BASH question

2010-10-18 Thread Tony Sceats
I think you want to use bc to calculate the percentage. the lines free_var=${free%.*}; total_var=${total%.*}; are removing everything after the decimal point, which leaves 2/2 * 100 which is of course 100% I presume it does this so that bash can then perform the arithmetic evaluation

Re: [SLUG] Shell math/BASH question

2010-10-18 Thread Tony Sceats
err, sorry, missed a closing quote per=`echo ($free/$total) * 100 | bc -l` On Tue, Oct 19, 2010 at 9:34 AM, Tony Sceats t...@fatuous.org wrote: I think you want to use bc to calculate the percentage. the lines free_var=${free%.*}; total_var=${total%.*}; are removing everything after

Re: [SLUG] Shell math/BASH question

2010-10-18 Thread peter
DaZZa == DaZZa dagi...@gmail.com writes: DaZZa free='/external process' total='external process' DaZZa free_var=$(free%.*); total_var=$(total%.*); DaZZa per=$(($free_var*100/$total_var)); DaZZa The per figure is the one I'm interested in - percentage free DaZZa space. You need to do the

Re: [SLUG] Shell math/BASH question

2010-10-18 Thread DaZZa
On Tue, Oct 19, 2010 at 9:38 AM, pe...@chubb.wattle.id.au wrote: DaZZa == DaZZa  dagi...@gmail.com writes: DaZZa free='/external process' total='external process' DaZZa free_var=$(free%.*); total_var=$(total%.*); DaZZa per=$(($free_var*100/$total_var)); DaZZa The per figure is the one I'm

Re: [SLUG] Shell math/BASH question

2010-10-18 Thread Nick Andrew
On Tue, Oct 19, 2010 at 09:00:16AM +1100, DaZZa wrote: The results from the third party software query are assigned as variables in the script and converted into round numbers as below free='/external process' total='external process' Course they're not numbers if they look like '2.47T' or