Main Page Content
Worried About High Disk Usage
Well if your running on a *nix box then here isa little cron job that will warn you when usagegets high!Now assuming you're root, create a sub-dir calledscripts.In this directory place the following scriptand data files.
===========df.script===============#!/bin/bashPATH=/sbin:/usr/sbin:/usr/bin:/bincd /root/scriptsif test `df | fgrep -c -f/home/mashton/df.txt` -eq 0then exit 0else df | mail "$1" -sDANGER_HIGH_DISK_USAGEfi===========df.script===============The script is executing df (which displays yourdisk usage), and pipes it through fgrep (whichscans the output line by line). I've used the -c(which counts the number of matches) and -f (whichtells fgrep to get the matching data from afile).The if condition tests for a value of 0 (nomatches) being returned by the fgrep. If 0 exitelse run df and email it to whoever you pass thrufrom 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 fgrepto match for. As you can see I'm testing foranything greater then 80% usage.This gives you ample time to either clean up orplan for another drive, before you get into the90% range. Since, this is where *nix filesystemperformance starts to slow down.Also the reason for going to beyond 100% isthat typically a *nix filesystem has an overflowbuffer which allows for more then 100%capacity. There is typically up to an extra 8% notreported.Remember to do a change mod on the df.script soit will run!Now just add it to your crontab and your readyto go!Just do: crontab -eThen insert a line for when you want it run (Irun mine every half hour and send the failureemail to alternating people) and whoever you wantit sent to.
=========crontab insert===========15 * * * * /root/scripts/df.script bryan &>/dev/null45 * * * * /root/scripts/df.script mike &>/dev/null=========crontab insert===========By setting this up you can avoid a suddensuprise and having your system crap out onyou!
Mike