Monitoring Disk Usage In Linux

One of the routine job of a Linux administrator to monitor the Disk space continuously. Normal people will write a simple script to check the disk space and report to system administrator through email. Good Idea,but here i am telling a new one which will continuously monitor your Disk and report if it cross a preset value. This will run as a cronjob.

#Script for monitoring Disk Usage
#Author BipinDas,Arab Open University.
# set alert level 80% is default
df -H | grep -vE ‘^Filesystem|tmpfs|cdrom’ | awk ‘{ print $5 ” ” $1 }’ | while read output;
#echo $output
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) $(hostname -i) as on $(date)” |
mail -s “Alert: Almost out of disk space $usep ” $ADMIN

Save it as in your scripts folder.

Open Crontab Editor

vi /etc/crontab

*/5 * * * * root /path/to/script/

Perfect,This will frequently check your Disk and inform once it cross the limit.

%d bloggers like this: