Check Disk Script

10:08 PM

#!/bin/bash
# Modified in to a script for checking disk usage and alert if disk usage goes beyond 85% for warnings and
# 90% for critical alerts
 
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
GOOD=84
WARNING_MIN=85
WARNING_MAX=89
 
DISK=`df -h | grep -A 1 $1  | awk '{print $4}' | sed /^$/d | tr -d "%"`
 
     if [ "$DISK" -lt "$GOOD" ]; then
         MESG="Status: Good, disk usage OK"
         RESP=$STATE_OK
     elif [ "$DISK" -ge "$WARNING_MIN" ]  &&  [ "$DISK" -lt "$WARNING_MAX" ]  ; then
         MESG="Status: WARNING, disk usage high"
         RESP=$STATE_WARNING
        else
        MESG="Status: CRITICAL, disk usage very high"
         RESP=$STATE_CRITICAL
     fi
echo "$MESG | diskspace=$DISK"

You Might Also Like

0 comments

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results