0

Although this error is quite common and explained almost everywhere on the web I've decided to ask a new question since I can't get a clue for this specific case.

I'm trying to get some data out of Zimbra Collaboration Suite and the only way I can do it is via bash.

Being my first time with bash I find it a bit hard to deal with.This is the code:

#!/bin/bash

all_account=`zmprov -l gaa`;
declare -i szquota
szquota=524288000
for account in ${all_account}
do
        mb_size=`zmmailbox -z -m ${account} gms`;
        set -i size;
declare -i quota
declare -i quota2
        for size in ${mb_size}
        do
                if [ $((10#$size)) -gt $((10#$szquota)) ] ; then
                        quota=`zmprov ga ${account} zimbraMailQuota`;
quota2="10#`zmprov ga ${account} zimbraMailQuota`";
                        echo "${account},${mb_size},$quota2\n";
                fi
        done
done

and this is the response:

line 12: 137,08: value too great for base (error token is "08")

I need to print all the accounts that have a quota of more than 500MB, and the output should be like this: account/quota/used quota.

Since mb_size is an array of values I can't figure out how I could convert its content to a decimal base as I did with the other values? It probably is much simpler than my mind makes it look but I really can't get out of this trouble. Kind regards

EDIT:

Thanks @Alfe!

I've modified the code like this:

#!/bin/bash

all_account=`zmprov -l gaa`;

szquota=524288000
for account in ${all_account}
do
        mb_size=`zmmailbox -z -m ${account} gms`;
        declare -i quota
        declare -i quota2
        for sizeStr in ${mb_size}
        do
        if [ $size -gt $((10#$szquota)) ] ; then # <--- line 13
                        quota=`zmprov ga ${account} zimbraMailQuota`;
quota2="10#`zmprov ga ${account} zimbraMailQuota`";
                        echo "${account},${mb_size},$quota2\n";
                fi
        done
done

but it returns another error: line 13: [: -gt: unary operator expected

I've also tried to enclose the values inside the if clause between quotation marks but if I'm not wrong bash interprets the content of quotation marks as a string and gives back this:

line 13: [: : integer expression expected

I'm sure I'm getting closer to a solution but I'm still stuck at the moment.

1 Answers1

0

You declared the variable size as integer with set -i size. Later you try to assign a value which then is checked for being a valid integer, it isn't, then you get the error. In your case, one of the values in ${mb_size} is the string 08 which is then interpreted as a bad octal value.

I suggest you let the loop run over a different variable which is not declared as int (so the for statement won't posed a problem), then as first statement you assign the string value of the loop variable properly so that it does not get interpreted as octal:

for sizeStr in ${mv_size}
do
    size=$((10#$sizeStr))
    if [ $size -gt $((10#$szquota)) ]
    then
        …

You could of course also just remove the declaration of the variable as integer. This probably would also solve the issue.

Alfe
  • 56,346
  • 20
  • 107
  • 159
  • `set -i size` actually just sets `$1` equal to the string "size" while (I think) ignoring the `-i` flag. – chepner Oct 02 '13 at 12:58
  • Yeah, I guess that somewhere a `declare -i size` is in the actual code. – Alfe Oct 02 '13 at 14:31
  • Hi guys, thanks for your answers! I've edited the post with the changes I made according to your suggestions but I'm still stuck for some reasons. By not declaring the variable as integer it returns `line 13: [: -gt: unary operator expected` but if I try to enclose the variables between quotation marks it returns `line 13: [: : integer expression expected` I know I'm just a beginner but it's really driving me nuts – user2822969 Oct 04 '13 at 09:13
  • Debug by outputting what you've got in your variables. Probably you've got sth like `137,08` in your variable. – Alfe Oct 04 '13 at 21:31