I'm having an infuriating issue with number comparison. Basically I've written a script that runs in cygwin that SSH's to 4 servers, figures out a success percentage and if it is less than a certain point, triggers an alarm. I've managed to get it to connect to the servers, figure out the percentage and create the if statements. Unfortunately what should be the easiest part, comparing the numbers is driving me crazy.
Here is the script (i've added the part about printing the variables to help debug):
The script runs without throwing an errors, but the logic doesn't work. If the current number is below 97 it does set off the alarm, but it also sets off the alarm if the percentage is 100 or higher. At first I thought it was something to do with the script only understanding integers, but that doesn't seem to be the case. I've tried every combination of single ([) brackets and double ([[) brackets I can think of and still getting the same thing. I've also tried quoting and not quoting the variables, but still the same errors.
I know that this is going to be something stupid...but I'm pulling my proverbial hair out here...
Thanks for the try. I tried "-lt" as well and it didn't work. I don't have the output in front of me right now, but it would throw and actual error instead of just triggering the wrong response.
edit:
I get the following when I use -lt (and no quotes around anything)
[~]$ ./bkcheck.orig
99.9219
99.7949
99.8012
99.8723
./bkcheck.orig: line 28: [[: 99.9219: syntax error: invalid arithmetic operator (error token is ".9219")
As of 23:43:48,Brooklyn VOD is streaming at 99.9219%
./bkcheck.orig: line 36: [[: 99.7949: syntax error: invalid arithmetic operator (error token is ".7949")
As of 23:43:49,Queens VOD is streaming at 99.7949%
./bkcheck.orig: line 44: [[: 99.8012: syntax error: invalid arithmetic operator (error token is ".8012")
As of 23:43:49,S.Manhattan VOD is streaming at 99.8012%
./bkcheck.orig: line 52: [[: 99.8723: syntax error: invalid arithmetic operator (error token is ".8723")
As of 23:43:49,N.Manhattan VOD is streaming at 99.8723%
That works but not if there are decimal places it fails. and I still don't understand why there were times when the var would be 100 and it would still fail.
I understand that the issue is it only works with integers, but there must be a way to compare non integers...or worst case round off to the closest whole number.
Greetings Experts,
I need to handle the views created over monthly retention tables
for which every new table in YYYYMMDD format, there is
equivalent view created and the older table which might be
dropped, the view over it has to be re-created over a dummy
table so that it doesn't fail.... (2 Replies)
Hi all,
currently I'm facing a issue in linking a .so file.
In my build machine, I've libcrypto.so.6 and there is a softlink as libcrypto.so.
In my make file I'm trying to link to the lib using -L -lcrypto and it is success and created my test.exe.
When I copy this test.exe to other... (4 Replies)
Hi All,
I am trying to compare two negative numbers using awk on linux.But it is giving me wrong result.Same code is working perfectly on solaris.
print ((0+new_price) < MIN_PRICE)
e.g If I try to compare -1.32(new_price) and -500(min_price) using "<" operator, output is 1 i.e true.
... (5 Replies)
I am trying to run following script in ksh on darwin 11.4.2:
freeSpace=2469606195
spaceNeeded=200
] && echo "no space" || echo "space available"
] && echo "no space" || echo "space available"
"-lt" is giving wrong answer as "no space" Whereas '<' works fine. When I change the freespace... (4 Replies)
Can someone please help me with a unix logic for below. I tried to get the desired output by using change capture condition in Datastage but its not working properly. i have two files file1, file2 as below.
file1
ROW_NO VEND_NO CODE AIR_D OCEAN_D
----------------------------------------
1 ... (3 Replies)
Hi,
I was trying to do a string comparison using if. However, the comparison result is getting treated as a executable statement. I'm not sure where I'm making the mistake!
$ typeset TEST_VAR='YUP'
$ if ; then echo 'Got It!'; fi;
ksh: : not found.
Any help is appreciated! (3 Replies)
Hi,
I am comparing two numbers, but it gives strange results:
My Code:
if
then
echo "True"
else
echo "False"
fi
This code gives False for the follwoing comparison
where as True for the following:
Any reason for this? Both Should have given False...
I am using... (9 Replies)
I use standard C random number generation logic in my application.
long nCounter;
long lRndNo;
char rand;
srand48(nCounter);
lRndNo = lrand48();
sprintf(rand,"%010.10d",lRndNo);
However we always find that the rand generated starts with '0','1' or '2'. I could not logically prove if... (1 Reply)