The below bash script, when executed, will check the % of disk space usuage of the complete filesystem and email a specified email address if more than 80% full.
Pre-req – create fs_report.log inside /var/log/
i.e.
touch /var/log/fs_report.log
Create a new bash script:
vim /path/to/script/diskspace.sh
Replace the email address or modify the disk space below as needed:
#!/bin/bash
#
#Extract % use for the filesystem
#Send email warning to if the raid is 80% or more full
#Include Folder/File sizes of the filesystem directory contents
#
df -h | awk '{ print $5 }' | cut -d'%' -f1 | while read usep; do
if [ $usep -ge 80 ]; then
echo "***$(hostname) is $usep% FULL at $(date)" > /var/log/fs_report.log
echo "***Please remove unnecessary data from $(hostname)" >> /var/log/fs_report.log
echo "***Detailed Folder/File size for BackupServer content:" >> /var/log/fs_report.log
df -h >> /var/log/fs_report.log
mail -s "WARNING-bksvr2 $usep% FULL" backup@mydomain.com < /var/log/fs_report.log -- -f "backup@mydomain.com"
fi
done
*Make sure to make the script executable:
chmod +x diskspace.sh
To automate this script add a cron job to run it on a regular basis:
0 8 * * * /path/to/script/diskspace.sh
The above cron job will run the script at 8am everyday.
Recent Comments