LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Disk space checking script? (https://www.linuxquestions.org/questions/linux-general-1/disk-space-checking-script-164554/)

jimieee 03-31-2004 10:12 AM

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

mako747 03-31-2004 10:46 AM

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.

jimieee 04-01-2004 02:57 AM

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


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