Skip to page content or Skip to Accesskey List.

Main Page Content

Worried About High Disk Usage

Posted on 09 Sep 1999

in Backend

by Mike Ashton (mashton)

Rated 3.74 (Ratings: 1)

Want more?

Mike Ashton

Member info

User since: 30 Aug 1999

Articles written: 2

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

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.org Evolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.

AltStyle によって変換されたページ (->オリジナル) /