This is an updated version of the more complicated original version immediately below this link. I like and now use this more simplified version.
- Set THRESH parameter to the percent of how full a volume is before an email is sent.
- Update the 2nd line (none|cdrom|qgscanner) to remove volumes you do not care about and do not want to be notified of.
I use cron to check during business hours of disk space issues.
# ----------------------------------------------
# -- Monitor disk space of drives and shares ---
# ----------------------------------------------
5,15,25,35,45,55 8-16 * * 1-5 /oracle/scripts/diskAlert.sh
diskAlert.sh
#!/bin/sh
THRESH=95;
df -PH | grep -vE 'none|cdrom|qgscanner' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [[ $usep -ge $THRESH ]]; then
echo -e "$(date) Threshold $THRESH% exceeded. \nRunning out of space on \"$partition ($usep%)\" on $(hostname)" |
mail -s "Alert: `uname -n` low on disk space $usep%" email@company.com
fi
done
Example of email when volume exceeds thhreshold:
Alert: halfmoon low on disk space 98%
Fri Dec 8 05:40:03 PST 2019 Threshold 95% exceeded.
Running out of space on "sharename.com:/mydrive20/LarryEllison (98%)" on halfmoon
No comments:
Post a Comment