Need help on Linux script to monitor hard drive space

I'm new to Linux and have very limited experience with shell scripts in general. I am taking a class and I have to research online and come up with a shell script that monitors disk space. I also have to be able to explain it line by line. I've researched various sites and came across this shell script. I typed it in and saved it but when I try to run it I get this error message: line 10: [: Use: integer expression expected. Line 10 is this one:

if [ $usep -ge $ALERT ]; then

Now that line uses the output from line 8, as well as the defined variable from line 4. Now line 4 is an integer, and when I look at line 8, it looks like it should resolve be an integer...so I can't figure out what is wrong here. Any help would be appreciated.

#!/bin/bash
# comment
ADMIN="(I have an email address here)"
ALERT=90
df -H | grep -vE '^none' | awk ' { print $5 " " $1 }' | while read output;
do
           #echo $output
           usep=$(echo $output | awk ' { print $1 }' | cut -d'%' -f1 )
           partition=$(echo $output | awk '{ print $2 }' )
           if [ $usep -ge $ALERT ]; then
                     echo "Running out of space \"$partition ($usep%)\" on$(hostname) as on $(date)"|
                               mail -s "Alert: Almost out of disk space $usep" $ADMIN
           fi
done

You can try forcing the issue this way:

# First declare usep as an integer
typeset -i usep 
usep=$(echo $output | awk ' { print $1 }' | cut -d'%' -f1 )

That seems to have worked. Thanks.

Just out of curiosity, do you have any idea why it didn't work as originally scripted? It seems to me that it should have evaluated out to an integer so I'm not understanding what went wrong.

for this warning " message: line 10: [: Use: integer expression expected "
i think it because bash shell cant read -gt,-lt, etc
u can use ksh so they can read it

and i've tried that script before but im using ksh shell
like this

#!/bin/ksh
# comment
ADMIN="(I have an email address here)"
ALERT=90
df -H | grep -vE '^none' | awk ' { print $5 " " $1 }' | while read output;
do
           #echo $output
           usep=`(echo $output | awk ' { print $1 }' | cut -d'%' -f1 )`
           partition=`(echo $output | awk '{ print $2 }' )`
           if [ $usep -ge $ALERT ]; then
                     echo "Running out of space \"$partition ($usep%)\" on$(hostname) as on $(date)"|
                               mail -s "Alert: Almost out of disk space $usep" $ADMIN
           fi
done

hope this can help u :smiley: