Check space of directories and send email if it has reached threshold limit

Hi,

I need help in writing unix script for checking space of some directories on the system and also send an email when it reaches the threshold limit.

I have written the followng code;

 
#!/bin/ksh
ADMIN="me@somewhere.com"
# set alert level 80% is default
THRESHOLD=80
df | grep -E "Filesystem|tmpfs|cdrom" | 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 $THRESHOLD ]; 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

When I run the above code I get the following error;

dspace.ksh[15]: Iused: bad number

df | sed -n '2,$s/\(.[^ \t]*\)\(.*\) *\(100%\|[89][0-9]%\)[ \t]*\(.*\)/\1 \3/p' | mail -s "partitions more than 80%" root

Hi Kurumi,

Sorry, I could not understand what was written and where in the code I could fit that. Can you please explain. Please bear with me as I am a beginner. Thanks.

first check if this command is working for you:

df | sed -n '2,$s/\(.[^ \t]*\)\(.*\) *\(100%\|[89][0-9]%\)[ \t]*\(.*\)/\1 \3/p'

df | grep "[89][0-99]%" | awk '{ print $1,"mounted on",$6,"has exceeded 80%"}' | mail -s "partitions more than 80%" user

Hi asalman,

I tried the following command;

df | grep "[89][0-99]%" | awk '{ print $1,"mounted on",$6,"has exceeded 80%"}' | mail -s "partitions more than 80%" user 

There is no mail in my mail. Remember, I want this mail to be sent to my email which is on lotus notes and in gmail.

I then tried the following commang;

 
df | grep "[89][0-99]%"

and find that it is picking the records which are more than 80% but does not include the ones which are 100%. I want to include all records that have reached 80% to 100%.

Please let me know. Thanks