Script for calculating disk usage

Hi,
I have home folders under /export/home/*.
I need to have  script that will check for disk usage of each folder, user1. Test to see if its over 2GB and if it is then mail the owner of the folder say tom@mydomain.com. This will have to be done recursively for all users in the directory /export/home.

Thanks,
--Walter
LVL 1
wfaleiroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mightyoneCommented:
0
mightyoneCommented:
if not use something like this, as for the time beeing i am on windows client you will have to alter alot

:-)
function sendmail has to be added by you,try 'man mail' for hints. but still think using quota is better

#!/bin/sh
#loop dirs
for i in `ls -al /export/home` do
  #check size
 if [ du -sh $i -gt 2000000000 ]; then
  echo "$i is full"
  sendmail($i)
  fi
done

0
wfaleiroAuthor Commented:
Hi,
I cannot use quotas as it will be implemented on an entire parition. The home directory is a sub directory on the partition, with other directories like source for cvs present. These will also come into picture when quotas are implemented.

Regards,
--Walter
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ahoffmannCommented:
du -h  /export/home/user1 | awk -F/ 'NF==3{print}'
du -h  /export/home/ | awk -F/ 'NF==3{print}'
0
wfaleiroAuthor Commented:
That produces no output at all.
0
ahoffmannCommented:
please post some lines from (10 or so, at least containing one with just a directory path)
  du -h /export/home/user1
0
cjl7freelance for hireCommented:
Hi Tom,

Here is a script that will do what you want, "fix" the SUBJECT and the BODY. You might wanna add the "@mydomain.com" after $i in "mail $i..."

//jonas

#!/bin/bash

# limit
LIMIT=42000 #2GB
SUBJECT="Your homedir is to large"
BODY="You need to delete stuff..."
cd /export/home/
for i in *
do
TEST=`du -sk $i|awk '{print $1}'`
if [ $TEST -gt $LIMIT ]; then
mail $i -s "$SUBJECT" <<EOF
$BODY
EOF

fi
done
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.