LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-31-2004, 10:12 AM   #1
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Rep: Reputation: 15
Disk space checking script?


Hi,

before I go spending time writing a script to do it, can anyone recommend an easy way to get notifications sent to me when a mounted device reaches a certain threshold? Say, for example, 85%.

Thanks,

James
 
Old 03-31-2004, 10:46 AM   #2
mako747
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware
Posts: 92

Rep: Reputation: 15
Hi.

I use this one on our servers.

It gives daily diskusage (not 85%) but you could modify it if you like.

#!/usr/bin/perl

$HOST=`cat /etc/HOSTNAME`;
chomp($HOST);
@retval=`df -h`;
$dt=`date`;
chomp($dt);
open(MAIL,"|/usr/lib/sendmail -t");
print MAIL "From: diskusage\@mydomain.com\n";
print MAIL "To: me\@mydomain.com\n";
print MAIL "Subject: Disk Space ($HOST)\n";
print MAIL "\n";
print MAIL "@retval\n\n";
print MAIL "$HOST\n";
close (MAIL);

I run it as a cron every night.
 
Old 04-01-2004, 02:57 AM   #3
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
Thanks, looks interesting. I wasn't aware that you could send mail like that

I came up with my own script, it isn't very elegant but it does the job. I added it to my cron.daily/ so it gets sent to me in the email for that:

#!/bin/bash

# Find those lines which contains the word "dev" (i.e. everything, but
# the table header)
df | grep dev > out.tmp

# Create results.tmp/wipe it if it already exists.
echo "WARNING FILESYSTEM IS LOW!!!" > results.tmp

# Try to match all the conditions that you want to flag
cat out.tmp | grep '100%' >> results.tmp
cat out.tmp | grep '99%' >> results.tmp
cat out.tmp | grep '98%' >> results.tmp
cat out.tmp | grep '97%' >> results.tmp
cat out.tmp | grep '96%' >> results.tmp
cat out.tmp | grep '95%' >> results.tmp
cat out.tmp | grep '94%' >> results.tmp
cat out.tmp | grep '93%' >> results.tmp
cat out.tmp | grep '92%' >> results.tmp
cat out.tmp | grep '91%' >> results.tmp
cat out.tmp | grep '90%' >> results.tmp
cat out.tmp | grep '89%' >> results.tmp
cat out.tmp | grep '88%' >> results.tmp
cat out.tmp | grep '87%' >> results.tmp
cat out.tmp | grep '86%' >> results.tmp
cat out.tmp | grep '85%' >> results.tmp

cat results.tmp

rm -f out.tmp
rm -f results.tmp

I know, I know I could improve it with some iteration but right now I really need to get on with some other stuff

Thanks,

James
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Best program for checking available disk space? TippyToes Linux - Software 5 11-16-2004 09:57 PM
Checking Disk Space thru console boyblitz Linux - Newbie 2 04-06-2004 11:39 AM
Checking disk space timberwolf Linux - General 9 12-04-2003 01:18 AM
Checking free disk space hackersapien Linux - Newbie 2 08-05-2003 01:38 AM
script for checking disk space pralaydesai Linux - Networking 3 03-25-2003 03:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration