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

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2007 > Using -lt with integers "integer expression expected"??





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Using -lt with integers "integer expression expected"??
mostro713@gmail.com

2007-11-16, 7:22 pm

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
Chris F.A. Johnson

2007-11-17, 1:27 am

On 2007-11-17, mostro713@gmail.com wrote:
>
> 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?


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

> 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


You should be comparing $i, not $disk.

> echo "Error"
> <send email goes here>
> fi
> done


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://cfaj.freeshell.org/shell/>
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
mostro713@gmail.com

2007-11-17, 1:27 am

On Nov 16, 8:35 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> On 2007-11-17, mostro...@gmail.com wrote:
>
>
> 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://cfaj.freeshell.org/shell/>
> 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


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

Thank you...

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com