division by 0 error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting division by 0 error
# 1  
Old 01-22-2009
Bug division by 0 error

Hi,
I am writing a script that among other things will be checking for various files on mount points. One of the conditions is that unless the server has failed over the df command will show root ( / ). If when checking the files the script comes across /, I want it to skip it, otherwise to complete the printf statement.
This portion of the script is

if ${MNTD} == "/" then
> /dev/null
else

printf '%12 ......
When running, if the script comes across a / I am receiving a 'Division by 0' error and it will abort the query.
Any suggestions would be greatly appreciated.
Thanks
# 2  
Old 01-22-2009
Quotes?

Try quoting the camparison variable
Code:
if "${MNTD}" == "/" then

Jerry
# 3  
Old 01-22-2009
Quote:
Originally Posted by cat55
I am writing a script that among other things will be checking for various files on mount points. One of the conditions is that unless the server has failed over the df command will show root ( / ). If when checking the files the script comes across /, I want it to skip it, otherwise to complete the printf statement.
This portion of the script is

Please put code inside [code] tags (and forget all that silly FONT and SIZE crap).
Quote:
Code:
 if ${MNTD} == "/" then
        > /dev/null
 else
        printf '%12 ......


However, since that really isn't code ...
Quote:
When running, if the script comes across a / I am receiving a 'Division by 0' error and it will abort the query.

Why would you be using any of the mount points as a divisor?

Code:
[ "$MNTD" = / ] || printf ...

Or:

Code:
if [ "$MNTD" != / ]
then
   printf ...
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Division by zero attempted error during linear conversion of values between 0.25 to 1

I want to implement the below formula with awk oneliner new_value = ((old_value - old_min) / (old_max - old_min) ) * (new_max - new_min) + new_min I want to pass the value of old_min and old_min as variable. Here is what I did for this old_min=$(awk 'BEGIN{a=100000000000}{if ($10<0+a) a=$10}... (2 Replies)
Discussion started by: sammy777888
2 Replies

2. Shell Programming and Scripting

awk - continue when encountered division error

Hello, How can I add a logic to awk to tell it to print 0 when encountering a division by zero attempted? Below is the code. Everything in the code works fine except the piece that I want to calculate read/write IO size. I take the kbr / rs and kbw / ws. There are times when the iostat data... (5 Replies)
Discussion started by: tommyd
5 Replies

3. UNIX for Dummies Questions & Answers

Help in division

hi, The below commands result only the whole number(not giving the decimal values). pandeeswaran@ubuntu:~$ echo 1,2,3,4|sed 's/,/\//g'|bc 0 pandeeswaran@ubuntu:~$ echo 1000,2,3|sed 's/,/\//g'|bc 166 How to make it to return the decimal values? Thanks (5 Replies)
Discussion started by: pandeesh
5 Replies

4. Shell Programming and Scripting

awk division error - 0

input 0 0 9820373 2069 0 0 11485482 awk '{print ($1/$3) / ($4/$7)}' input error Is there any way to fix this problem ? (25 Replies)
Discussion started by: quincyjones
25 Replies

5. Shell Programming and Scripting

division by zero

Hello, I am searching for a way to calculate for example 10/100 within a shellscript and the result should be 0.1 and not just 0. Every alternative i tried just results 0 Thank you in advance 2retti (6 Replies)
Discussion started by: 2retti
6 Replies

6. Shell Programming and Scripting

awk error message: division by zero attempted

Hi, I'm executing unixbench tool v4.1 on an embedded system and I'm getting these error messages: Execl Throughput 1 2 3awk: /unixbench/unixbench-4.1.0/pgms/loops.awk:38: (FILENAME=- FNR=4) fatal: division by zero attempted Pipe Throughput 1 2 3 4 5 6 7 8 9 10awk:... (3 Replies)
Discussion started by: rogelio
3 Replies

7. Shell Programming and Scripting

Division by zero error message in AWK

How can I modify my awk code to get rid of the divion by zero error message? If I run the script without an input file, it should return error message "Input file missing" but not divison by zero. Code: #!/bin/nawk -f BEGIN { if (NR == 0) {print "Input file... (4 Replies)
Discussion started by: Pauline mugisha
4 Replies

8. UNIX for Dummies Questions & Answers

Division Error - Integer Error?

Hi All, I'm reasonably new to UNIX, and am having problems with a TSHELL script that I am using. The script is intended to cycle through a loop, and then divide the number in the counter by 10 and store the result in another variable. I am missing something simple here, but cannot work it out... (1 Reply)
Discussion started by: Col
1 Replies

9. Shell Programming and Scripting

error "awk: (FILENAME=- FNR=23) fatal: division by zero attempted"

Hi , I have file : after i run this command : there are error can we print blank line if output error ?? thanks.. ^^ (4 Replies)
Discussion started by: justbow
4 Replies

10. Shell Programming and Scripting

division problem

how can i show the value when i divide a number where the dividend is greater then the divisor. for example... 3 divided by 15 ---> let x=3/15 when i do this in the shell environment it gives me an output of 0. please help me. thanks. (3 Replies)
Discussion started by: inquirer
3 Replies
Login or Register to Ask a Question