[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 installing a new system, and where the old
system had disk space measured in gigabytes, this one returns values
in terabytes - and therein lies the problem.

The results from the third party software query are assigned as
variables in the script and converted into round numbers as below

free='/'
total=''

free_var=$(free%.*);
total_var=$(total%.*);

per=$(($free_var*100/$total_var));

The "per" figure is the one I'm interested in - percentage free space.

Now, with the system which returns gigabytes, this gives a good enough
result from the first two variables to get close enough for the people
who are managing the system, vis-a-vis

web4:~ # echo $free
25.40G
web4:~ # echo $total
61.14G
web4:~ #

Which gives a good enough result of 40% free.

With the NEW system, the results are somewhat different

web4:~ # echo $free
2.47T
web4:~ # echo $total
2.70T
web4:~ # echo $free_var
2
web4:~ # echo $total_var
2
web4:~ # echo $per
100
web4:~ #

Which gives a figure of 100% free - not a good thing.

So, after this long and involved description, my question for those
with much greater nouse than myself is - is there any way to take
these operations

free_var=${free%.*};
total_var=${total%.*};

so it returns 2.4 and 2.7 respectively instead of 2 and 2?

Note that I didn't write the original script, so please, no comments
of 'You should have done this" or "This way is better' - I'm not in a
position to make wholesale changes to the script concerned to make it
"better". I'm not modifying it at the moment - simply copying bits
from the script and pasting them into another terminal window to get
the output without changing the script itself.

Any advice regarding changing the math appreciated.

Thanks.

DaZZa
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Flashplayer 10

2010-10-18 Thread brett




So, once again, do I just copy the new ``libflashplayer.so'' to the

plugin site in mozilla, change the permissions to root, and 0755, or
am I missing out something?  Will I wreck my browser's flashplay
ability or something equally unthinkable?

Hi,
Yes just replace the libflashplayer.so with the new version. You should not 
need to change permissions. On newer versions of Firefox you can put in folder 
/home/username/.mozilla/plugins (create plugins folder if it does not exist) 
and it will work once you restart Firefox.
Brett.

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


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

per=$(($free_var*100/$total_var));

with only integers, since bash does not do floats

if you replace it with something like

per=`echo "($free/$total) * 100 | bc -l`

then you should be able to get the percentage.

Of course this is no longer pure bash, you now also need bc installed, but I
think it's pretty much everywhere by default.

On Tue, Oct 19, 2010 at 9:00 AM, DaZZa  wrote:

> 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 installing a new system, and where the old
> system had disk space measured in gigabytes, this one returns values
> in terabytes - and therein lies the problem.
>
> The results from the third party software query are assigned as
> variables in the script and converted into round numbers as below
>
> free='/'
> total=''
>
> free_var=$(free%.*);
> total_var=$(total%.*);
>
> per=$(($free_var*100/$total_var));
>
> The "per" figure is the one I'm interested in - percentage free space.
>
> Now, with the system which returns gigabytes, this gives a good enough
> result from the first two variables to get close enough for the people
> who are managing the system, vis-a-vis
>
> web4:~ # echo $free
> 25.40G
> web4:~ # echo $total
> 61.14G
> web4:~ #
>
> Which gives a good enough result of 40% free.
>
> With the NEW system, the results are somewhat different
>
> web4:~ # echo $free
> 2.47T
> web4:~ # echo $total
> 2.70T
> web4:~ # echo $free_var
> 2
> web4:~ # echo $total_var
> 2
> web4:~ # echo $per
> 100
> web4:~ #
>
> Which gives a figure of 100% free - not a good thing.
>
> So, after this long and involved description, my question for those
> with much greater nouse than myself is - is there any way to take
> these operations
>
> free_var=${free%.*};
> total_var=${total%.*};
>
> so it returns 2.4 and 2.7 respectively instead of 2 and 2?
>
> Note that I didn't write the original script, so please, no comments
> of 'You should have done this" or "This way is better' - I'm not in a
> position to make wholesale changes to the script concerned to make it
> "better". I'm not modifying it at the moment - simply copying bits
> from the script and pasting them into another terminal window to get
> the output without changing the script itself.
>
> Any advice regarding changing the math appreciated.
>
> Thanks.
>
> DaZZa
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


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  wrote:

> 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
>
> per=$(($free_var*100/$total_var));
>
> with only integers, since bash does not do floats
>
> if you replace it with something like
>
> per=`echo "($free/$total) * 100 | bc -l`
>
> then you should be able to get the percentage.
>
> Of course this is no longer pure bash, you now also need bc installed, but
> I think it's pretty much everywhere by default.
>
> On Tue, Oct 19, 2010 at 9:00 AM, DaZZa  wrote:
>
>> 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 installing a new system, and where the old
>> system had disk space measured in gigabytes, this one returns values
>> in terabytes - and therein lies the problem.
>>
>> The results from the third party software query are assigned as
>> variables in the script and converted into round numbers as below
>>
>> free='/'
>> total=''
>>
>> free_var=$(free%.*);
>> total_var=$(total%.*);
>>
>> per=$(($free_var*100/$total_var));
>>
>> The "per" figure is the one I'm interested in - percentage free space.
>>
>> Now, with the system which returns gigabytes, this gives a good enough
>> result from the first two variables to get close enough for the people
>> who are managing the system, vis-a-vis
>>
>> web4:~ # echo $free
>> 25.40G
>> web4:~ # echo $total
>> 61.14G
>> web4:~ #
>>
>> Which gives a good enough result of 40% free.
>>
>> With the NEW system, the results are somewhat different
>>
>> web4:~ # echo $free
>> 2.47T
>> web4:~ # echo $total
>> 2.70T
>> web4:~ # echo $free_var
>> 2
>> web4:~ # echo $total_var
>> 2
>> web4:~ # echo $per
>> 100
>> web4:~ #
>>
>> Which gives a figure of 100% free - not a good thing.
>>
>> So, after this long and involved description, my question for those
>> with much greater nouse than myself is - is there any way to take
>> these operations
>>
>> free_var=${free%.*};
>> total_var=${total%.*};
>>
>> so it returns 2.4 and 2.7 respectively instead of 2 and 2?
>>
>> Note that I didn't write the original script, so please, no comments
>> of 'You should have done this" or "This way is better' - I'm not in a
>> position to make wholesale changes to the script concerned to make it
>> "better". I'm not modifying it at the moment - simply copying bits
>> from the script and pasting them into another terminal window to get
>> the output without changing the script itself.
>>
>> Any advice regarding changing the math appreciated.
>>
>> Thanks.
>>
>> DaZZa
>> --
>> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
>> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>>
>
>
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Shell math/BASH question

2010-10-18 Thread peter
> "DaZZa" == DaZZa   writes:


DaZZa> free='/' total=''

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.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Shell math/BASH question

2010-10-18 Thread DaZZa
On Tue, Oct 19, 2010 at 9:38 AM,   wrote:
>> "DaZZa" == DaZZa   writes:
> DaZZa> free='/' total=''
>
> 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


[SLUG] Flashplayer

2010-10-18 Thread Malcolm Johnston
Hi

I've copied the new libflashplayer.so to its plugin directory, but something 
is not working.  I get a message that I need to download a new flashplayer 
from Adobe, but that's what I've done.

Restoring the older *.so gets me back to par, so no damage has been done; it 
seems, however, that I must be missing something.

One possibility is that my Firefox is also in need of an upgrade; it's been 
there since 2007, so that is very possible.

That's about all I can think of.  Suggestions would be welcome, but I suspect 
it's the Firefox version that's the problem.  I know the *.so that I 
downloaded isn't corrupt, as I downloaded two of them, and they "cmp"-ed
without any message.

Cheers,
Malcolm Johnston
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Flashplayer

2010-10-18 Thread Troy Rollo
On Tuesday 19 October 2010 17:20:28 Malcolm Johnston wrote:
> I've copied the new libflashplayer.so to its plugin directory, but
> something is not working.  I get a message that I need to download a new
> flashplayer from Adobe, but that's what I've done.

What is the message (the words, not the summary)?

Try typing "about:plugins" in the URL bar to see if it is in fact picking up 
the new version.

Are there any messages in ~/.xsession-errors that could be related to the 
problem?

-- 

Regards, 
Troy Rollo 
Solicitor 
Parry Carroll 
Commercial Lawyers 
Direct: (02) 8257 3177 
Fax: (02) 9221 1375 
Switch: (02) 9221 3899 
E-mail: t...@parrycarroll.com.au 
Web: www.parrycarroll.com.au 

Liability limited by a scheme approved under Professional Standards 
Legislation 

This message and any attachments are confidential to Parry Carroll. If you 
have received it my mistake, please let us know by reply and then delete it 
from your system. You must not copy the message, alter it or disclose its 
contents to anyone. Thank you.

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


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='/'
> total=''

Course they're not numbers if they look like '2.47T' or '25.40G'.

Do "df -k -P -T" and grab the size & available as 3rd and 5th
values on each output line; they're integers and high enough
resolution for most purposes.

Nick.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html