Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with BC

Status
Not open for further replies.

clarenz

Technical User
Nov 5, 2002
4
AU
Folks

I have extracted some raw data from our servers and wish to do some simple arithmetic to it. The end result that I wish to get is

1. The amount of data that is presently used.
2. The amount allocated to them
3. The % of data that is used of allocated space.

I can extract the first two fields fairly easily, but I am not able to get the calculation right with "bc". I am able to use bc "interactively" i.e. from the command line, but when I introduce variables to it, it refuses to process the data. Can you please assist? Thanks.

#-------------------------------------------------
# Declare variables
#-------------------------------------------------
PASSWD='*****'
RAW='/home/clarence/docs/scripts/tmp/qreport_server1.txt'
LIMIT='/home/clarence/docs/scripts/tmp/limit.txt'
USAGE='/home/clarence/docs/scripts/tmp/usage.txt'

#-------------------------------------------------
# Get the information from the filers
#-------------------------------------------------
rsh server1 -l root:$PASSWD "quota report -t" > /home/clarence/docs/scripts/tmp/qreport_server1.txt

#-------------------------------------------------
# Grep out needed information
#-------------------------------------------------
grep -i group_one $RAW | awk '{print $6}' > $LIMIT
grep -i group_one $RAW | awk '{print $5}' > $USAGE


# echo "scale=4;6/3" | bc --> this works.
# echo "scale=4;$USAGE/$LIMIT" | bc --> DOES NOT work. Why?
# PERCENT=`bc $USAGE/$LIMIT \*100` --> this does not work

#-------------------------------------------------
# Generate the report
#-------------------------------------------------
echo "Quota Report for FM_group"
echo "Current data usage is: " `cat "$LIMIT"`
echo "Quota limit is set to: " `cat "$USAGE"`
echo
echo "Percentage of Data to Quota Limit is: " `cat "$PERCENT"`

 
#PERCENT=`bc $USAGE/$LIMIT \*100` --> this does not work
USAGE and LIMIT are filenames not values
`bc \`cat $USAGE\`/\`cat $LIMIT\`\*100`
should work
PS: do not abuse of "
-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Thanks for your time, Jamisar. I have tried your suggestion and it did not work, but we are getting close :) Following is the output.

> ./quota_report.sh
File 98712344/132120576*100 is unavailable.
Quota Report for FM_group
Current data usage is: 132120576
Quota limit is set to: 98712344
Percentage of Data to Quota Limit is: %
 
sure
VAL=`echo "\`cat $USAGE\`/\`cat $LIMIT\`\*100" | bc`
a ` inside a ` has to be masked
-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Jamisar

This the latest output.

> ./quota_report.sh
(standard_in) 1: illegal character: Quota Report for FM_group
Current data usage is: 132120576
Quota limit is set to: 98712344
Percentage of Data to Quota Limit is: %

I think the illegal character it is referring to is the one to remove the special character for the division sign i.e. \*100 because when I remove this from the equation, I get the output:

> ./quota_report.sh
Quota Report for FM_group
Current data usage is: 132120576
Quota limit is set to: 98712344
Percentage of Data to Quota Limit is: 0%

I am trying various other combinations at the moment. Thank you for your continued time and patience.

 
post the output of your quota-cmd -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
PER=`echo "\`cat $USAGE\`/\`cat $LIMIT\`" | bc`

The ouput of the above is this:
> ./quota_report.sh
Quota Report for FM_group
Current data usage is: 132120576
Quota limit is set to: 98712344
Percentage of Data to Quota Limit is: 0%

PER=`echo "\`cat $USAGE\`/\`cat $LIMIT\`\*100" | bc`

And the output of this (your latest suggestion), I have

> ./quota_report.sh
(standard_in) 1: illegal character: Quota Report for FM_group
Current data usage is: 132120576
Quota limit is set to: 98712344
Percentage of Data to Quota Limit is: %

The rest of the code has remained static.
 
#!/bin/sh
....
....
AAA=`cat $USAGE`
case $AAA in [0-9]|[1-9][0-9]*) ;; *) exit ;; esac
BBB=`cat $LIMIT`
case $BBB in [0-9]|[1-9][0-9]*) ;; *) exit ;; esac
CCC=`echo "scale=4;($AAA * $BBB)/100"|bc`
echo $AAA
echo $BBB
echo $CCC -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top