Sponsored Content
Top Forums Shell Programming and Scripting Stupid issue with number comparison Post 302324468 by DeCoTwc on Wednesday 10th of June 2009 10:58:14 PM
Old 06-10-2009
Stupid issue with number comparison

Hello all,

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):

Code:
(22:42:27\[DeCo@deco)
[~]$ cat bkcheck.orig 
#!/usr/bin/bash
bkc ()
{
ssh dncsb tail -1 /dvs/dncs/tmp/PerformanceMonitoring/dsmperfmon.csv|awk -F, '{print ($3 / $4) * 100}'
}
qnc ()
{
ssh dncsq tail -1 /dvs/dncs/tmp/PerformanceMonitoring/dsmperfmon.csv|awk -F, '{print ($3 / $4) * 100}'
}
smc ()
{
ssh dncss tail -1 /dvs/dncs/tmp/PerformanceMonitoring/dsmperfmon.csv|awk -F, '{print ($3 / $4) * 100}'
}
nmc ()
{
ssh dncsn tail -1 /dvs/dncs/tmp/PerformanceMonitoring/dsmperfmon.csv|awk -F, '{print ($3 / $4) * 100}'
}
bkerrors=`bkc`
qnerrors=`qnc`
smerrors=`smc`
nmerrors=`nmc`
echo $bkerrors
echo $qnerrors
echo $smerrors
echo $nmerrors
while true;do
if 
[[ "$bkerrors" < "97" ]];then
 cygstart bk.wav
printf "Uh-oh, at `date +%H:%M:%S` Brooklyn VOD is streaming at $bkerrors%%\n"
sleep 5
else 
printf "As of `date +%H:%M:%S`,Brooklyn VOD is streaming at $bkerrors%%\n"
fi
if
[[ "$qnerrors" < "97" ]];then
cygstart qn.wav
printf "Uh-oh, at `date +%H:%M:%S` Queens VOD is streaming at $qnerrors%%\n"
sleep 5
else
printf "As of `date +%H:%M:%S`,Queens VOD is streaming at $qnerrors%%\n"
fi
if
[[ "$smerrors" < "97" ]];then
 cygstart sm.wav
printf "Uh-oh, at `date +%H:%M:%S` S.Manhattan VOD is streaming at $smerrors%%\n"
sleep 5
else
printf "As of `date +%H:%M:%S`,S.Manhattan VOD is streaming at $smerrors%%\n"
fi
if
[[ "$nmerrors" < "97" ]];then
 cygstart nm.wav
printf "Uh-oh, at `date +%H:%M:%S` N.Manhattan VOD is streaming at $nmerrors%%\n"
sleep 5
else
printf "As of `date +%H:%M:%S`,N.Manhattan VOD is streaming at $nmerrors%%\n"
fi

sleep 300
clear
bkerrors=`bkc`
qnerrors=`qnc`
smerrors=`smc`
nmerrors=`nmc`
done

[~]$ ./bkcheck.orig 
99.9454
100
99.8703
99.3868
As of 22:45:23,Brooklyn VOD is streaming at 99.9454%
Uh-oh, at 22:45:24 Queens VOD is streaming at 100%
As of 22:45:30,S.Manhattan VOD is streaming at 99.8703%
As of 22:45:30,N.Manhattan VOD is streaming at 99.3868%

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...
 

9 More Discussions You Might Find Interesting

1. Programming

random number logic -- issue

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)
Discussion started by: asutoshch
1 Replies

2. UNIX for Advanced & Expert Users

Strange Number comparison issue

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)
Discussion started by: shihabvk
9 Replies

3. Shell Programming and Scripting

Issue with String Comparison (if)

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)
Discussion started by: waterdrop
3 Replies

4. Shell Programming and Scripting

comparison of number in linux..

hi all experts, i=1; while do echo $i $i=$i+1 done can I use min=2 max=5 if (($min > $ max)) then else (2 Replies)
Discussion started by: hamnsan
2 Replies

5. Shell Programming and Scripting

Issue with files comparison, help me with a logic

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)
Discussion started by: JSKOBS
3 Replies

6. Shell Programming and Scripting

Number comparison in ksh on mac with -lt is giving wrong answer

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)
Discussion started by: sabitha
4 Replies

7. Shell Programming and Scripting

Negative number comparison using nawk on Linux

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)
Discussion started by: Rashmee
5 Replies

8. Linux

Linking issue due to so version number

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)
Discussion started by: vijkrr
4 Replies

9. Shell Programming and Scripting

awk - 2 files comparison without for loop - multi-line issue

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)
Discussion started by: chill3chee
2 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 11:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy