Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am at work right now, and my superiors asked me to write/find a shell script for the Red hat Server edition that checks a folder size, and if it's above a certain limit, it will send an email.Can anyone here help me find or help me create a script like that??

I thank you in advance,

Jayakrishnan T

share|improve this question
1  
This should get you started: du -sc /path/to/dir/ | grep total | awk '{print $1}' Stick that in a for loop with an if statement and a "mail" command. Be better if you make it send one email with a list of all the dirs that are oversized though, rather than one each. –  Sirex May 18 '11 at 6:51
    
thanks for your reply.. –  Jayakrishnan T May 25 '11 at 6:38

3 Answers 3

Are you already running Nagios?

Check out check_dirsize or check_filesize_dir:

http://exchange.nagios.org/directory/Plugins/Uncategorized/Operating-Systems/Linux/CheckDirSize/details

http://exchange.nagios.org/directory/Plugins/Uncategorized/Operating-Systems/Linux/check_filesize_dir/details

Both could be easily adapted to run out of cron if you like.

share|improve this answer
    
This is really a good information,but i question is different.Thanks for your reply –  Jayakrishnan T May 19 '11 at 4:33
#!/bin/bash
DIR=/path/to/dir
SIZE=10000
MAILADDR="mail@domain.com"
if [ $(du -s $DIR | awk '{print $1}') -gt $SIZE ]; then
    echo "$DIR" | mail -s "Directory limit exceeded in $DIR" $MAILADDR
fi

SIZE has to be given in Bytes!

share|improve this answer
    
This Script is not working,the file is hanged while executing. –  Jayakrishnan T May 18 '11 at 11:16
    
mh. I tested, but it works on my system. make sure that mail and du is installed and see whats happen use: bash -x ./script to see further details –  noqqe May 20 '11 at 11:32

I would think that inotifywait(1) from inotify-tools would be helpful here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.