Using -lt with integers "integer expression expected"??
am 17.11.2007 02:14:28 von mostro713
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"
fi
done
Thanks in advance
Re: Using -lt with integers "integer expression expected"??
am 17.11.2007 02:35:06 von cfajohnson
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"
>
> 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
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
Re: Using -lt with integers "integer expression expected"??
am 17.11.2007 06:17:06 von mostro713
On Nov 16, 8:35 pm, "Chris F.A. Johnson" wrote:
> On 2007-11-17, mostro...@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"
> >
> > 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
> 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...