Simple Shell Scripts Monitor Hard Disk on Linux
TAG : Simple Shell Scripts Monitor Hard Disk on Linux
Example Solutions :
vim /root/disk_monitor.sh
input line below :
#########################################################
#!/bin/sh
# of space is >= 90%
#
ADMIN=”email@domain.com” # –> Your Email Admin
# alert level 90%
ALERT=90
df -H | grep -vE ‘^Filesystem|tmpfs|cdrom’ | awk ‘{ print $5 ” ” $6 }’ | while read output;
do
#echo $output #uncomment with debug
usep=$(echo $output | awk ‘{ print $1}’ | cut -d’%’ -f1 )
partition=$(echo $output | awk ‘{ print $2 }’ )
if [ $usep -ge $ALERT ]; then
echo “Running out of space ”$partition ($usep%)” on $(hostname) as on $(date)” |
mail -s “Alert: Linux Server out of disk space $usep%” $ADMIN
fi
done
#########################################################
Run Every 30 Minute on Crontab
#crontab -e
input line below :
#monitor disk
*/30 * * * * /bin/sh /root/disk_monitor.sh >/dev/null 2>&1
save now and Success Solutions
If disk usage over 90% then alert mail to ADMIN Email
Add A Comment