Email Directory UK

linux shell script: how do i check home directory size and email user if its too big?

I am trying to write a shell script that evaluates the size of each user's home directory and if it is greater than 50 MB I want an email to be sent to their user account telling them that they need to reduce the size of their home directory. I am mainly having trouble with using the output of du -s /home/* to compare each size to 50mb and then sending an email to that user, any help would be fantastic thank you.

Public Comments

  1. Don't do it (quite) that way. Read /etc/passwd, and use sed or awk (for example) to extract the home directory of each user. If the directory exists, and is readable, run du on it, with "du -s <directory>". Feed that into sed again, extracting the first item (size), Note that the size in in 1K bytes, multiply by 1024 to get the size in bytes. awk -F : '{print $1 " " $6}' </etc/passwd >tmp will print a list of users and home directories awk '{print $1}' <tmp >tmpusers will extract the user names from the above output and awk '{print $2}' <tmp >tmpdirs for d in `cat tmpdirs`; do du -s $d; done >tmpsizes will capture sizes along with home directories You can then use "join" to combine the results.
Powered by Yahoo! Answers