This script is used to check the mount points space status without mail alert. Save the mount points name in mn.log file before running this script.

#!/bin/bash
rm mn1.log
rm diff.log
df -h |awk ‘{print $6}’|grep -v Mounted >>mn1.log
comm -13 mn.log mn1.log 1>>diff.log 2>/dev/null
if [ ! -s diff.log ]

then

for ml in `cat mn.log`

do

usedSpc=`(echo $(df -h $ml|awk ‘{print $5}’|grep -v capacity|cut -d “%” -f1 -))`
case $usedSpc in
[7-8][5-9])
diskStatus=”SPACE GETTING LOW AT MOUNT POINT: $ml —— :$usedSpc%”
echo -e “\e[1;32m $diskStatus \e[0m” >>mntst.log
;;
[9][0-8])
diskStatus=”WARNING, RUNNING OUT OF SPACE AT MOUNT POINT: $ml —— :capacity $usedSpc%”
echo -e “\e[1;31m $diskStatus \e[0m” >>mntst.log
;;
[1][0][0])
diskStatus=”MOUNT POINT FULL.. NO SPACE LEFT AT MOUNT POINT: $ml —— : $usedSpc%”
echo -e “\e[1;31m $diskStatus \e[0m” >>mntst.log
;;
*)

esac
done

else
echo -e “\e[1;31m MOUNT POINT MISSING : `comm -13 mn.log mn1.log` \e[0m” >>mntst.log

fi

*********make changes in code based on your env and Test this script in dev before use this in prod***********

Recommended Posts

Start typing and press Enter to search