simple nagios script to check disk usage in solaris

i know that there already is a command in nagios to check file system usage, but it gives you the percentage in the wrong format (it says there is 21% free when i am used to it saying that 79% is being used)

this will give you the format in basic df per device

usage of script : $0 <device>

example: diskcheck.sh /var

tested in nagios 2.3 – 2.5

#!/bin/bash

TMP_FILE0=/tmp/disk_usage0.$$
TMP_FILE2=/tmp/disk_usage2.$$

while [ ! -z "$1" ]; do
df $1 -h | grep $1 | sed -e 's/%//g' | awk '{if ($5 > 90) print $0}' \
 >>$TMP_FILE0
df $1 -h | grep $1 \
 >>$TMP_FILE2
shift
done

   if [ `cat $TMP_FILE0 | wc -l` -gt 0 ]; then

        if [ `cat $TMP_FILE0 | awk '{print $5}' | sed -e 's/%//g'` -ge 95 ]; then
                cat $TMP_FILE0
                rm -f $TMP_FILE0
                rm -f $TMP_FILE2
                exit 2          
        else
                cat $TMP_FILE0
                rm -f $TMP_FILE0
                rm -f $TMP_FILE2
                exit 1          
        fi

   else
      cat $TMP_FILE2
      rm -f $TMP_FILE0
      rm -f $TMP_FILE2
      exit 0
   fi
«
»

    Leave a Reply

    Your email address will not be published. Required fields are marked *