Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Are you already running Nagios?

Check out check_dirsize or check_filesize_dir:

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
if [ $(du -s $DIR | awk '{print $1}') -gt $SIZE ]; then
    echo "$DIR" | mail -s "Directory limit exceeded in $DIR" $MAILADDR

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


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.