Main Page Content
Worried About High Disk Usage
Rated 3.74 (Ratings: 1)
Want more?
- More articles in Backend
Now assuming you're root, create a sub-dir called
scripts.In this directory place the following script
and 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 your
disk 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 (no
matches) 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 fgrep
to match for. As you can see I'm testing foranything greater then 80% usage.This gives you ample time to either clean up or
plan 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% is
that 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 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 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 sudden
suprise and having your system crap out onyou!Mike