![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what does the operation '>&' mean in a shell script | cy163 | UNIX for Dummies Questions & Answers | 3 | 05-17-2008 10:54 AM |
| Problem in division | rochitsharma | UNIX for Dummies Questions & Answers | 8 | 08-10-2006 12:16 PM |
| division in shell scripts | esham | Shell Programming and Scripting | 6 | 11-30-2005 02:42 AM |
| Cannot adjust division | jav_v | Filesystems, Disks and Memory | 1 | 08-20-2002 05:50 AM |
| division problem | inquirer | Shell Programming and Scripting | 3 | 04-02-2002 07:03 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
division operation in shell script
Hi guys
I am trying to divide 2 variables that I got during the execution of script, but I unable to divide the variables. pls help. Hers is the code. Code:
num_tasks=`sqlplus -s batch_user/batch_user@acsblest << EOF1 set heading off SET FEEDBACK OFF SET PAGESIZE 0 SET LINESIZE 900 select cp_num_run_ from fusionhc_chk where cc_alias = 'eCustomerCMEObjMgr_enu'; EOF1` echo $num_tasks max_tasks=`sqlplus -s batch_user/batch_user@acsblest << EOF2 set heading off SET FEEDBACK OFF SET PAGESIZE 0 SET LINESIZE 900 select cp_max_task from fusionhc_chk where cc_alias = 'eCustomerCMEObjMgr_enu'; EOF2` echo $max_tasks per_load=$num_tasks/$max_tasks echo $per_load if [ "$per_load" -gt "0.95" ] then echo "not good" fi exit Code:
3 20 3/20 |
| Forum Sponsor | ||
|
|
|
|||
|
try this for Integer division
per_load=$(($num_tasks/$max_tasks))
This would give you only integer out put. Not sure if direct decimal o/p is possible . You could use awk to get the desired decimal out. --Manish |
|
|||
|
First off, SQL provide for division:
Code:
result=\
`sqlplus -s batch_user/batch_user@acsblest << EOF1
set heading off
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
select cp_num_run_ / cp_max_task
from fusionhc_chk
where cc_alias = 'eCustomerCMEObjMgr_enu';
EOF1`
echo $result
Code:
result=`echo "$num_tasks / max_tasks " | bc -l` echo $result |
|
|||
|
thank you guys.. i modified the code as follows and got the output, but still i am unable to compare the two numbers, VGERSH, i know you explained this part.. but I am sorry to tell that I am unable to understand theat part. my understanding of shell script is very poor.
I used sql to do the division. here is the code and set -x output. Code:
num_tasks=`sqlplus -s batch_user/batch_user@$SIEBEL_DB_ORACLESID << EOF2
set heading off
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
select cp_num_run_ / cp_max_task
from fusionhc_chk
where cc_alias = 'eCustomerCMEObjMgr_enu';
EOF2`
echo $num_tasks
set -x
if [ $num_tasks > 0.95 ]
then
echo "not good"
fi
exit
Code:
.15 + [ .15 ] + 1> 0.95 + echo not good not good + exit |