Using -lt with integers "integer expression expected"??

Using -lt with integers "integer expression expected"??

Post by mostro71 » Sun, 18 Nov 2007 10:14:28


Hi all,

I am trying to put together a simple script that will send an email
when disk space falls below a certain percentage. I'm receiving an
error "24: integer expression expected". From what I read it has to do
with -lt thinking the values in brackets are not integers. Aren't
they? Can you provide me with some assistance.

#!/bin/bash

disk=`df -h -x cifs -x iso9660 | grep -E ^/dev | awk '{ print $4 }' |
sed 's/G//g'`

#[Loop]

for i in $disk
do
if [ "$disk" -lt 20 ]; then
echo "Error"
<send email goes here>
fi
done

Thanks in advance
 
 
 

Using -lt with integers "integer expression expected"??

Post by Chris F.A. » Sun, 18 Nov 2007 10:35:06


Are they? Have you looked at the output of 'df -h'?


You should be comparing $i, not $disk.


min=20000000
df -x cifs -x iso9660 |
while read fs bl u a pc mp
do
if [ "$a" -lt "$min" ]
then
echo "Error"
...
fi
done


--
Chris F.A. Johnson, author < http://www.yqcomputer.com/ ;
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

 
 
 

Using -lt with integers "integer expression expected"??

Post by mostro71 » Sun, 18 Nov 2007 14:17:06


Yes, what a mistake... Changing $disk for $i makes a huge
difference..:)
A second pair of eyes always helps..

Thank you...