On Tue, Oct 19, 2010 at 9:38 AM, <[email protected]> wrote: >>>>>> "DaZZa" == DaZZa <[email protected]> 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 calculation before rounding, and as shell arithmetic > works only in integers, that's a little problematic. > > I'd be tempted to write a `normalise' function that converts to > gigabytes. This one assumes `disk' terabytes of 1000 gigabytes each. > > normalise() > { > case "$1" in > *.?T) # Terabytes, one dec place > echo $1 | sed -e 's/T$//' -e 's/\.\([0-9]\)/\100/' > ;; > *.??T)# Terabytes, two dec place > echo $1 | sed -e 's/T$//' -e 's/\.\([0-9][0-9]\)/\10/' > ;; > *G) # Gigabytes > echo $1 | sed 's/G$//' > ;; > esac > } > > > Then do free_var=`normalise $free` > etc.
That worked perfectly Peter, thanks a million. DaZZa -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
