I have a 1 Terabyte raid with number of users. The problem is a users files may not be only in their $HOME dir but in several others. I would like suggestions of ways to find out a users disk use, du is not much help because of above. I have the following script that I adapted from a google search which seems on the right track. But with a users disk use in the 100s of GB it will return incorrect values, probably because of unsigned ints?
Any suggestions very greatfully received....
#!/bin/bash
# by D. Michael McIntyre aka Silvan
silvan@windows-sucks.com
# Adapted and shamelessly changed by kebabhead
# root test
if [ `whoami` != 'root' ]
then
cat << EOF
This script must be run with root privledge
Aborting...
EOF
exit 1
fi
USERLIST="user_list.txt"
if [ ! -f $USERLIST ]
then
cat << EOF
AIEEEEEEEEE! The list of users does not exist!
Aborting...
EOF
exit 1
fi
# read user list
cat $USERLIST | {
while read USER; do
if [ $USER = 'root' ]
then
cat << EOF
Searching for files owned by root will cause problems
Aborting...
EOF
exit 1
fi
# temp file used because I couldn't get all the pipes to work without it
tmp="/tmp/diskhog.tmp"
[ -f $tmp ]&&rm -f $tmp
# find all user files, then stat them, and save output to $tmp
echo "Finding all files owned by $USER... This will take a bit of time."
find /home -user $USER -exec stat {} \; > $tmp 2> /dev/null
total=0
outnum=0
# calculate usage
echo "Calculating total usage..."
# read $tmp, search for lines with "Size" then generate a list of the
# actual file sizes to be totaled.
list=`gawk '$1 == "Size:" {print}' $tmp|gawk '{print $2}'`
# now add them up...
for record in $list
do
((total+=$record))
done
# now output results, nicely formatted.
printf "Total disk usage for %s is %u bytes. \n" $USER $total
done
}
exit 0