Main Page Content
Worried about High Disk Usage???
Rated 3.74 (Ratings: 1) (Add your rating)
Log in to add a comment
(1 comment so far)
Well if your running on a *nix box then here is a little cron job that will warn you when usage gets high!
Now assuming you're root, create a sub-dir called scripts.
In this directory place the following script and data files.
===========df.script=============== #!/bin/bash PATH=/sbin:/usr/sbin:/usr/bin:/bin cd /root/scripts if test `df | fgrep -c -f /home/mashton/df.txt` -eq 0 then exit 0 else df | mail "$1" -s DANGER_HIGH_DISK_USAGE fi ===========df.script===============
The script is executing df (which displays your disk usage), and pipes it through fgrep (which scans the output line by line). I've used the -c (which counts the number of matches) and -f (which tells fgrep to get the matching data from a file).
The if condition tests for a value of 0 (no matches) being returned by the fgrep. If 0 exit else run df and email it to whoever you pass thru from the command line (see crontab below).
===========df.txt=============== 104% 103% 102% 101% 100% 99% 98% 97% 96% 95% 94% 93% 92% 91% 90% 89% 88% 87% 86% 85% 84% 83% 82% 81% ===========df.txt===============
Now in the data file I've set what I want fgrep to match for. As you can see I'm testing for anything greater then 80% usage.
This gives you ample time to either clean up or plan for another drive, before you get into the 90% range. Since, this is where *nix filesystem performance starts to slow down.
Also the reason for going to beyond 100% is that typically a *nix filesystem has an overflow buffer which allows for more then 100% capacity. There is typically up to an extra 8% not reported.
Remember to do a change mod on the df.script so it will run!
Now just add it to your crontab and your ready to go!
Just do: crontab -e
Then insert a line for when you want it run (I run mine every half hour and send the failure email to alternating people) and whoever you want it sent to.
=========crontab insert=========== 15 * * * * /root/scripts/df.script bryan &> /dev/null 45 * * * * /root/scripts/df.script mike &> /dev/null =========crontab insert===========
By setting this up you can avoid a sudden suprise and having your system crap out on you!
Mike


