Linux: How to monitor the disk usage

In time the disk usage of servers increase and if you do not monitor regularly due to insufficiant disk space your server may not function properly. In order to not to face such trouble it is necessary to follow the disk usage all the time by just creating the shell script file below and adding it to crontab to run the script periodically. According to your needs you may change the alert value. Do not forget to set an email account in the script.


    1. ADMIN="" # Set admin email so that you can get email.
      ALERT=75 # set alert level 75%
      # Exclude list of unwanted monitoring, if several partions then use "|" to separate the partitions.
      # An example: EXCLUDE_LIST="/dev/hdd1|/dev/hdc5"
      function main_prog() {
      while read output;
      usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
      partition=$(echo $output | awk '{print $2}')
      if [ $usep -ge $ALERT ] ; then
      echo "Server disk usage \"$partition ($usep%)\" on server $(hostname), $(date)" | \
      mail -s "Warning: Server disk usage is in critical level $usep%" $ADMIN
      # ======================================
      if [ "$EXCLUDE_LIST" != "" ] ; then
      df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | main_prog
      df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}' | main_prog
  • Add the following line to crontab to run the script every hour:

    1. 0 * * * * /root/scripts/>/dev/null

    Bir cevap yazın

    E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir