Ok, to start with I'm not much of a programmer, so bare with me if this script is a bit sloppy and longer than it need be. The script is supposed to check a users quota usage on given partitions and then send a warning email if they are nearing their limit.

However, when I test the script, i get the following error
Code:
[ : : integer expression expected
I'm pretty sure the error is with the if/then comparison [ "$quota_usage" -gt $QUOTA_LIMIT ], but what's wrong, I don't know. Could it be that $quota_usage is a string and not an integer? If so, is it possible to cast $quota_usage as an integer, or is this asking too much of bash? I'm sure I'm overlooking something very simple, but like I said, I'm not much of a coder.

Here's the full script
Code:
#!/bin/bash

QUOTA_LIMIT=8960
MAIL_BODY="/etc/QuotaMail.txt"
MAIL_DIR="/var/spool/mail/"
WARNING_SUBJECT="WARNING: YOUR MAIL ACCOUNT IS REACHING ITS QUOTA LIMIT"
PARTITIONS="/dev/ida/c0d0p5 /dev/ida/c0d0p6"

awk -F: '{ print $1 }' /etc/passwd > /tmp/usernames
{
   while read username; do
      for i in $PARTITIONS; do
         block_usage=`quota $username | grep $i | awk -F' ' '{ print $2 }' | sed s/*//`
         if [ $block_usage -gt $QUOTA_LIMIT ]; then
            has_exceeded_quota_limit="yes"
         else
            has_exceeded_quota_limit="no"
         fi
      done
      if ! grep "$WARNING_SUBJECT" "$MAIL_DIR"$username &&
         [ "$has_exceeded_quota_limit" = "yes" ]; then
            cat $MAIL_BODY | mail -s "$WARNING_SUBJECT" $username
      fi
   done
} < /tmp/usernames && rm /tmp/usernames