Email alert when hard disk is full in linux
*******************************
Step 1: Create a bash script file
*******************************
nano /opt/diskspacealert.sh
*******************************
Step 2 : paste the below script
*******************************
#!/bin/sh
# refered https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
# enter your mailed below for email alert
ADMIN="admin123@gmail.com"
# set alert level 90% is default
ALERT=90
df -HP | grep -vE '^Filesystem|tmpfs|cdrom' |
while read partition size used free perc mnt ;
do
usep=$(echo $perc | tr -d '%' )
if [ $usep -ge $ALERT ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as
on $(date)" |
mail -s "Alert: Almost out of disk space - $usep%" $ADMIN
fi
done
Note *** change the admin123@gmail.com to your mail id to which you want email alert
*******************************
Step 3 : make the script executable
*******************************
chmod 755 /opt/diskspacealert.sh
*******************************
Step 4 : scheduling the scrip to run every day
*******************************
type crontab -e in the linux shell
then add the below line
0 10 * * * /opt/diskspacealert.sh
this will run the script every day 10 am
Note : ***
you must have installed and configured
Sendmail
mailx
Comments
Post a Comment