Sponsored Content
Top Forums Shell Programming and Scripting BC calculation for floating (invalid arithmetic operator ) Post 302976389 by alvintiow on Wednesday 29th of June 2016 03:14:25 AM
Old 06-29-2016
Hi Aia,

It is SUSE SLEH 11, I am comparing the 'number'.


Hi Don,

1. The below code is the actual full code showing this error (line 15 and 19)
Code:
#!/bin/ksh
str1=`uptime | awk '{print $10}'| sed 's/,//'`
str2=`uptime | awk '{print $11}'| sed 's/,//'`
str3=`uptime | awk '{print $12}'| sed 's/,//'`
 echo $str1
echo $str2
echo $str3
#warn_level='$str1*1.03' | bc
warn_level=`echo "$str1*1.03"|bc`
crit_level=`echo "$str1*1.05"|bc`
#crit_level='$str1*1.05' | bc
 if [[ "$crit_level" -gt "$str2" || "$crit_level" -gt "$str3" ]]; then
        status=2
        statustxt="CPU load is critical - $str1"
 elif [[ "$warn_level" -gt "$str2" || "$warn_level" -gt "$str3" ]]; then
        status=1
        statustxt="CPU load is Warning - $str1"
else
        status=0
        statustxt="CPU load is normal, no spike - $str1"
fi
 echo "$status CPULOAD_spike  PERFDATA=$str1 $statustxt"

2.
Code:
 /bin/ksh --version: version         sh (AT&T Research) 93u+ 2012-08-01

3. locale:
Code:
LANG=POSIX
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

4. uptime
Code:
15:02pm  up 77 days  0:26,  1 user,  load average: 1.82, 1.89, 1.88

Below is the exactly output from the code
Code:
1.82
1.89
1.88
./CPULOAD: line 15: [[: 1.91: syntax error: invalid arithmetic operator (error token is ".91")
./CPULOAD: line 15: [[: 1.91: syntax error: invalid arithmetic operator (error token is ".91")
./CPULOAD: line 19: [[: 1.87: syntax error: invalid arithmetic operator (error token is ".87")
./CPULOAD: line 19: [[: 1.87: syntax error: invalid arithmetic operator (error token is ".87")
0 CPULOAD_spike  PERFDATA=1.82 CPU load is normal, no spike - 1.82

I removed the comma due to when
Code:
awk '{print $10}'

the output consists of comma

Code:
uptime | awk '{print $10}'

below is the output
1.84,

Code:
uptime | awk '{print $10}'| sed 's/,//'

below is the output
1.84

Last edited by RudiC; 06-29-2016 at 05:50 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arithmetic in floating point

is it not possible to simply di aritmetic without using bc or awk i have tried folllowing operatrions but they support only integer types plz suggest me code for floating using values stored in the variables.the ans i get is integer and if i input floating values i get error numeric constant... (6 Replies)
Discussion started by: sumit the cool
6 Replies

2. Shell Programming and Scripting

Arithmetic calculation on real numbers in Bourne Shell Script

I am begining to learn bourne shell and as a practice I have written a script which when given the purchase price and percentage of discount calculates the savings. I somehow cannot figure out why my script fails to do arthimatic calculation on real numbers. Could anyone look at the script... (5 Replies)
Discussion started by: Tirmazi
5 Replies

3. UNIX for Dummies Questions & Answers

syntax error: invalid arithmetic operator

hi, i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line: let valor=$1 and the value passed is rules.txt the error is: let: valor=rules.txt: syntax error: invalid... (2 Replies)
Discussion started by: limadario
2 Replies

4. Shell Programming and Scripting

checking variables + arithmetic operator help

i'm trying to make a script to simply add numbers together for example i have a file script file called add add 1 2 3 4 5 15 however i want the user to put at least 3 numbers so i did this if then echo "please enter more than two numbers" exit 1 fi but it's telling me i have... (3 Replies)
Discussion started by: el3ctr0nic47
3 Replies

5. Programming

arithmetic calculation using awk

hi there again, i need to do a simple division with my data with a number of rows. i think i wanted to have a simple output like this one: col1 col2 col3 val1 val2 val1/val2 valn valm valn/valm any suggestion is very much appreciated. thanks much. (2 Replies)
Discussion started by: ida1215
2 Replies

6. Shell Programming and Scripting

floating point arithmetic operation error

I am writing a script in zsh shell, it fetchs a number from a file using the awk command, store it as a variable, which in my case is a small number 0.62000. I want to change this number by multiplying it by 1000 to become 620.0 using the command in the script var2=$((var1*1000)) trouble is... (2 Replies)
Discussion started by: piynik
2 Replies

7. Shell Programming and Scripting

Arithmetic calculation in variable

Hi, I am trying to do an addition to a value stored in a variable... var1=`grep -n "match" sample.txt|cut -d : -f1` var2=`echo $var1|cut -d " " -f1` (Here i want add +1 to the output value) (4 Replies)
Discussion started by: Kevin Tivoli
4 Replies

8. UNIX for Dummies Questions & Answers

Invalid arithmetic operator

Hi experts, I'm facing trouble with the below bash script, any help is appreciated #!/usr/bin/bash .. if (( "${date1}" > "${l_date1}" )) then echo "success" else echo "nothing" fi the variable date1 contains 08/06/2013 and l_date1 contains 10/08/2013 this small script to... (6 Replies)
Discussion started by: parpaa
6 Replies

9. UNIX for Beginners Questions & Answers

Invalid arithmetic operator on string concatenation

Hello. LEAP_VERSION="4.2" export ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' 'openSUSE-Leap-'"$LEAP_VERSION"'-Oss' 'openSUSE-Leap-'"$LEAP_VERSION"'-Update' 'openSUSE-Leap-'"$LEAP_VERSION"'-Update-Non-Oss')Seems that the - is interpreted as a numeric... (2 Replies)
Discussion started by: jcdole
2 Replies

10. OS X (Apple)

Gobsmacked by ksh93 floating point arithmetic.

Hi guys... I am working on limited basic set of maths routines for ksh93 that can be sourced as . ./ksh_math.sh and I am gobsmacked by its capabilities. Although some big guns may already know this, I didn't, and ksh93 is easily able to do floating point numbers to floating point powers and... (16 Replies)
Discussion started by: wisecracker
16 Replies
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy