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
ddi_iomin(9F)						   Kernel Functions for Drivers 					     ddi_iomin(9F)

NAME
ddi_iomin - find minimum alignment and transfer size for DMA SYNOPSIS
#include <sys/conf.h> #include <sys/ddi.h> #include <sys/sunddi.h> int ddi_iomin(dev_info_t *dip, int initial, int streaming); INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). This interface is obsolete. PARAMETERS
dip A pointer to the device's dev_info structure. initial The initial minimum DMAtransfer size in bytes. This may be zero or an appropriate dlim_minxfer value for device's ddi_dma_lim structure (see ddi_dma_lim_sparc(9S) or ddi_dma_lim_x86(9S)). This value must be a power of two. streaming This argument, if non-zero, indicates that the returned value should be modified to account for streaming mode accesses (see ddi_dma_req(9S) for a discussion of streaming versus non-streaming access mode). DESCRIPTION
The ddi_iomin() function, finds out the minimum DMAtransfer size for the device pointed to by dip. This provides a mechanism by which a driver can determine the effects of underlying caches as well as intervening bus adapters on the granularity of a DMA transfer. RETURN VALUES
The ddi_iomin() function returns the minimum DMAtransfer size for the calling device, or it returns zero, which means that you cannot get there from here. CONTEXT
This function can be called from user, interrupt, or kernel context. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Obsolete | +-----------------------------+-----------------------------+ SEE ALSO
ddi_dma_devalign(9F), ddi_dma_setup(9F), ddi_dma_sync(9F), ddi_dma_lim_sparc(9S), ddi_dma_lim_x86(9S), ddi_dma_req(9S) Writing Device Drivers SunOS 5.11 04 Apr 2006 ddi_iomin(9F)
All times are GMT -4. The time now is 04:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy