Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By djgerbavore at 2004-08-17 08:28
If you're maintaining a lot of server's with multiple hard-drives you'll need to know how to manage and watch your harddrives. You know it's getting full or needs cleaning before it's too late and your users can't complete their work because they're out of disk-space. Nothing is worse than franticly trying to reclaim disk-space because you ran out of it. This guide will hopefully aide you in a time-savinf manner.
First of all: check the usage of your hard-drive(s)!
As you can see my hda3 is at 82%. With the help of scripts you can have this task done at given times, and get an e-mail notification if the percentage of used disk-space reaches a certain threshold.
First we will make a basic bash script that will report if any paritions are over 80%.
Code:
#!/bin/bash
df | egrep "(100%|[89][0-9]%)"
The egrep statement will match any usage between 80% and 100%.
Now let's do this as a timed event:
Type crontab -e to start an empty file where you can add all your cron jobs. (for more info type man 5 crontab)
Now to make a basic cron job that will run everyday at 10p.m..
Code:
0 22 * * * df | egrep "(100%|[89][0-9]%)"
The first number, 0, indicates the minute, the second, 22, is the hour that your job is supposed to run at. The next three *'s are day of month, the month, and day of week respectively.
Finally to have this cron job email you if any of your partition's are filled 80% or more you just add the mail command, like so:
Hope you don't mind my editing too much
I corrected a few flaws in your cron explanation
and changed grep to egrep and made it match
100 as well.
Cheers,
Tink
by ddstyles on Sun, 2004-08-29 15:03
just a note on the first part of the cron entry:
the * means: run every possible time for this field.
i.e. 5 22 * * * means minute 5, hour 22, and then every day of the month, every month, and every day of the week.
If you added 5 22 15 * * the cron would only run on the 15th day of the month.
Duncan
by Tinkster on Sun, 2004-08-29 20:24
But then his tutorial isn't on cron, it's on automated
disk-space monitoring...
Cheers,
Tink
by circlecreek on Mon, 2004-08-30 03:15
I've been to a demo of a very impressive Monitoring solution by MetaMind in Basel. It's very efficient since even when everything fails, agents (they call metamon) continue to trace why this happened and will fill logs as soon as back online...
Wonder where that logs to when both hdd's and a
network-connections are gone
Btw, the homepage is atrocious.
by JZL240I-U on Thu, 2004-09-02 06:54
Nice as a whole. Being me and thus being lazy, I'd want to know in the mail which drive was how full without having to run the job again on my screen.
My first idea was to "tee" the second pipe and by that means insert the egrep-results into the mail. Could this be done by variables as well and how would they get their values assigned and introduced into the mail?
by Tinkster on Thu, 2004-09-02 21:28
Nichts leichter als das :}
[Nothing more easy than that :}]
Code:
0 22 * * * full=`df | egrep "(100%|[89][09]%)"` && mail -s "Warning, $full is filling up." you@emailaddr.com
Wirsing,
Tink
by JZL240I-U on Fri, 2004-09-03 02:06
Guten Morgen
[good morning ... ahm, should rather be good night in NZ]
Whoa, we are on the economic trip here .
Thank you for the solution.
Wirsing? Grütze an die Kiwis!
by Tinkster on Fri, 2004-09-03 02:17
I take it you liked my solution?
One is glad to be of service ...
Cheers,
Tink
Und Danke fuer die Gruetze ;}
by Kristijan on Tue, 2005-04-12 01:22
I sort have made my own rendition of this script. I only have it monitoring one volume though.
Code:
FS=/dev/hd2
USAGE=`df | grep $FS | awk '{ print $4 }' | sed "s/%//"`
PERCENT=90
if [ $USAGE -gt $PERCENT ]
then
echo $FS Filesystem on $HOSTNAME has reached "$PERCENT"% capacity | mail -s $HOSTNAME kristijan@fake.com
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
I corrected a few flaws in your cron explanation
and changed grep to egrep and made it match
100 as well.
Cheers,
Tink
the * means: run every possible time for this field.
i.e. 5 22 * * * means minute 5, hour 22, and then every day of the month, every month, and every day of the week.
If you added 5 22 15 * * the cron would only run on the 15th day of the month.
Duncan
disk-space monitoring...
Cheers,
Tink
Worth a check at: www.metamindsolutions.com
network-connections are gone
Btw, the homepage is atrocious.
My first idea was to "tee" the second pipe and by that means insert the egrep-results into the mail. Could this be done by variables as well and how would they get their values assigned and introduced into the mail?
[Nothing more easy than that :}]
Wirsing,
Tink
[good morning ... ahm, should rather be good night in NZ]
Whoa, we are on the economic trip here .
Thank you for the solution.
Wirsing? Grütze an die Kiwis!
One is glad to be of service ...
Cheers,
Tink
Und Danke fuer die Gruetze ;}
-Kristijan