Click to See Complete Forum and Search --> : What's wrong with this shell script?


Icarus
08-29-2002, 04:35 PM
#! /bin/sh
LINE=`bdf|grep usrtmp|awk '{print $4}'`
echo 'Current size of temp:' $LINE
echo 'doing test'
if [ "$LINE" > "4500000" ] ; then
echo 'tmp is too large'
else
echo 'tmp is ok'
fi

Granted this on an HP-UX system, where 'bdf' is simular to a 'df' and usrtmp is a single filesystem.
I only need this script to check the available field, which it does just fine (thats what the first echo was to determine). The problem is no mater what I throw at it, it will retun the 'tmp is too large' everytime. currently the size is about 3900000 so this should be returning 'tmp is ok'.

Can anyone see what/if I'm missing anything?

The output is...
$ ./test.sh
Current size of temp: 3939752
doing test
tmp is too large

Gaccm
08-29-2002, 04:44 PM
i'm pretty sure that in the if statement you are comparing a number to a string of numbers. Err, hmm... actually i think you are comparing 2 strings. ACtually I'm not sure, but i do know who should make sure you arn't using strings instead of numbers, as strings have weirdo math rules.

TGrimace
08-29-2002, 04:46 PM
Here's what I changed it to, and it worked for me.


#! /bin/sh
LINE=3939752
echo 'Current size of temp:' $LINE
echo 'doing test'
if [ $LINE -gt 4500000 ] ; then
echo 'tmp is too large'
else
echo 'tmp is ok'
fi


I took out the quotes (not sure if that did anything) and changed the = to -gt, the = has given me problems in the past.

Icarus
08-29-2002, 04:54 PM
RIGHT! Gaccm, thanks for pointing that out for me! I forgot that anything in quotes would be considered a string:rolleyes:

maybe I should start getting more sleep before I attack code :D
Good thing I don't do shell scripts for a living ;)

And thanks Grimace for the -gt statement, that was exactly what I was missing


Thanks guys!