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!

If statement doesn't act like it should... easy soln probably

Status
Not open for further replies.

SuaveRick

Programmer
Apr 12, 2004
142
CA
Hey there, I am writing a script to simply check the cpu usage of two processes. The script works fine except that it doesn't seem to be evaluating the variable like it should:

max=0.10
top -d1 -f cpu.dat #get the cpu usage of processes
grep lca < cpu.dat > lca.dat #search for the process
awk '{ print $11}' lca.dat > used.dat #print that to file
while read cpusage #read the file line by line to evaluate
do
echo $cpusage
if [ $cpusage -gt 0.10 ]
then
echo "gt .1"
else
echo "NOT gt .1"
fi
done < used.dat


This is what used.dat looks like:
0.29
0.27


I did a WC on it and it says there are 10 chars in the file so that means there are two trailing spaces after the last digit... I don't think that should matter but who knows... I used the tr -d command to take out the spaces but that didn't work either.

I'm fresh out of ideas, could it be the decimals?
 
In my opinion shell math is done on integer only.
You may consider using only awk:
top -d1 -f cpu.dat #get the cpu usage of processes
awk '/lca/ && $11>0.1' cpu.dat

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top