Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

korn shell maths issue

Status
Not open for further replies.

nimrodman

MIS
Nov 22, 2005
43
US
I am having a big problem with a script I am trying to do to check file space usage; I have in my script the following:

if [[ "$usage -gt max_range || $usage -eq "100"" ]]
then
send_eamil
fi

I can see the value in usage and max_range, but the difference does not come out properly, it sends the mail regardless if usage is above or below the criteria given, I have used double quotes as shown in the line of code above, I have used the {} around the variables, but no luck.

In a few words, could anyone help out by explaining the best way to solve this situation, thanks.
 
Perhaps this ?
if [ $usage -gt $max_range -o $usage -eq 100 ]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
nimrodman

There's nothing wrong with your syntax, I've tested (amoungt variants)
Code:
 if [[ 1 -eq 1 || 2 -eq 4 ]]; then echo yes; fi
on ksh on AIX 5.1

However, I believe this is part of the Korn shell so you might want to add to the start of your script a line like
Code:
#!/bin/ksh
which will force the script to use ksh.

To help with debugging try
Code:
#!/bin/ksh -xv
which will output the lines as interpreted so you can see what's going on.

On the internet no one knows you're a dog

Columb Healy
 
Well, if this is actually your code, you have several syntax problems.
Code:
if [[ "$usage -gt max_range || $usage -eq "100"" ]]
then
     send_eamil
fi
You've got the whole thing inside the "[[ ]]" quoted. There's no "$" in front of max_range. You are mixing strings and numeric tests.

You can code it like this if you want purely numeric tests.
Code:
#!/bin/ksh

typeset -i usage=$1
typeset -i max_range=${2:-500}

print "Usage=$usage, Max Range=$max_range"

if (( usage > max_range || usage == 100 )); then print "Yes"; fi

if (( usage > max_range )); then print "Usage over max range"; fi
if (( usage == 100 )); then print "Usage is 100"; fi
You can try it by passing different values on the command line to test.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top