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

link|improve this question

71% accept rate
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
feedback

3 Answers

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.

link|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
feedback
#!/bin/bash
DIR=/path/to/dir
SIZE=10000
MAILADDR="mail@domain.com"
if [ $(du -s $DIR | awk '{print $1}') -gt $SIZE ]; then
    mail -s "Directory limit exceeded in $DIR" $MAILADDR
fi

SIZE must be given in Bytes!

link|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
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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