Monitor Disk space using shell script

This script will help you to monitor disk space of your production server when it reach the set threshold limit, So that you could take initiative action at right time .
Create a script file with disk.sh and put this in crontab for auto check.

# vim /root/disk.sh
Host=`hostname`
Mail="salam843@gmail.com"
Space=`df -h | awk '{print $5}' | tail -n 1 | cut -d"%" -f1`
threshold="95"
partition="/dev/sdb5"
partition1="/dev/sda3"
if (( Space > threshold ))
then
echo "At $Host MailServerr of Disk $partition  has cross  the threshhold limit." | mail -s "Disk full aleart" "$Mail"
else
echo "Disk threshhold not reached"
fi

Set Script in Crontab

50 * * * * /bin/sh /root/.disk.sh

Monitor Multiple  Disk space using shell script

Host=`hostname`
Mail="salam843@gmail.com"
Space=`df -h | awk '{print $5}' | tail -n 1 | cut -d"%" -f1`
Space1=`df -h | awk '{print $5}' | head -n 2 |tail -n 1 | cut -d"%" -f1`
threshold="85"
partition="/dev/sdb5"
partition1="/dev/sda3"
if (( Space > threshold ))
then
echo "At $Host MailServerr of Disk $partition  has cross  the threshhold limit." | mail -s "Disk full aleart" "$Mail"
elif (( Space1 > threshold ))
then
echo "At $Host MailServerr of Disk $partition1  has cross  the threshhold limit." | mail -s "Disk full aleart" "$Mail"
else
echo "Disk threshhold not reached"
fi 
Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment