Email on diskspace almost full Linux
Create a script file like this one
#vi /scripts/diskalert.sh
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 85 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep%" stompersly@gmail.com
fi
done
Add a command to your cron
# crontab -e
0 7 * * * /scripts/diskAlert.sh
If you need to install mail
# sudo yum install mailx