Tag Archives: script for disk monitoring

Disk Space monitor script in Linux

Disk Space Monitoring Script for Linux Operating system

When ever disk space is going to low the following script will send a mail to the user show disk space low at which hostname and disk.

Script:

#!/bin/sh
#=================================================================================================

# Script Title  : Disk Space Monitoring
# Version       : 1.0
# Purpose       : Shell script to monitor disk space
# It will send an email to provided email IDs, if available percentage of free space is > /tmp/diskspace/space.txt
        echo "Date- $dt" >> /tmp/diskspace/space.txt
        echo "IP Address -`/sbin/ifconfig | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | egrep -v '255|(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})'`"  >> /tmp/diskspace/space.txt
        echo "Hostname - $(hostname)"  >> /tmp/diskspace/space.txt

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
# Checks if disk free is between 75% and 85%
  if [ $usep -gt 75 ] && [ $usep -le 85 ]; then
        echo "File System -$partition"  >> /tmp/diskspace/space.txt
        echo "Percent Used - $usep%"  >> /tmp/diskspace/space.txt
mailx -s "WARNING !! Low disk space on $(hostname)- $(date)" $EMAIL  > /tmp/diskspace/space.txt
        echo "Percent Used - $usep%"  >> /tmp/diskspace/space.txt
mailx -s "CRITICAL !! Low disk space on $(hostname)- $(date)" $EMAIL  > /tmp/diskspace/space.txt
echo "Percent Used - $usep%"  >> /tmp/diskspace/space.txt
mailx -s "HIGH CRITICAL !! Low disk space on $(hostname)- $(date)" $EMAIL  < space.txt
        fi
    fi
done