Disk Space

Hi

This is my script for disk space monitoring

clear

if [ $UID -ne 0 ]
then
echo "You must be root user to execute the script"
fi

ALERT_LEVEL=10
CONSUMPTION_LEVEL= `df -k | awk {'print $5'} | cut -d '%' -f1 | sed "1 d"`

for i in $CONSUMPTION_LEVEL
do
FILE_SYSTEM=`df -k | awk {'print $1'} | sed "1 d"`
if [ "$CONSUMPTION_LEVEL" -gt "$ALERT_LEVEL" ]
then
echo "The file system $FILE_SYSTEM has reached a consumption level of $CONSUMPTION_LEVEL"
fi
done

I am getting the following error while executing this

./Disk_Space_Mon: line 9: 11: command not found

CONSUMPTION_LEVEL= `df -k | awk {'print $5'} | cut -d '%' -f1 | sed "1 d"`

lose the space after the =

Do a loop of the filesystesm rather than the volume they occupy (done here for Linux, I grep for dsk instead of dev on Solaris):

clear

ALERT_LEVEL=10

if [ $UID -ne 0 ]; then
  echo "You must be root user to execute the script"
fi

for FILESYSTEM in `df -k | grep -v Filesystem | awk  '{ print $1 }' | grep "/dev/"`; do
  echo FILESYSTEM = $FILESYSTEM
  CONSUMPTION_LEVEL=`df -k | grep ${FILESYSTEM} | awk '{ print $5 }' | cut -d '%' -f1`
  echo CONSUMPTION_LEVEL = ${CONSUMPTION_LEVEL}
  if [ ${CONSUMPTION_LEVEL} -gt ${ALERT_LEVEL} ]; then
    echo "The file system ${FILE_SYSTEM} has reached a consumption level of ${CONSUMPTION_LEVEL}"
  fi
done

You may want to put "exit" in after:

echo "You must be root user to execute the script"

Example run:

You must be root user to execute the script
FILESYSTEM = /dev/sda5
CONSUMPTION_LEVEL = 31
The file system  has reached a consumption level of 31

Hi Jim mcnarama

Your suggestion worked. Thanks for that

Hi TonyFullerMalv

The code is really nice. I tested and it worked. Thank you very much