LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-05-2004, 12:54 PM   #1
kebabhead
LQ Newbie
 
Registered: Apr 2004
Location: west coast USA
Distribution: redhat 9, fedora core 2, Gentoo
Posts: 20

Rep: Reputation: 0
Question find disk usage per user on a filesystem


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
 
Old 08-05-2004, 02:47 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
find / -printf "%u  %s\n" | awk '{user[$1]+=$2}; END{ for( i in user) print i " " user[i]}'
Not quite as pretty as yours, but does the trick
( I think - I don't have a tera-byte raid at hand to
verify this ;}) ...



Cheers,
Tink
 
Old 08-05-2004, 03:30 PM   #3
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
Why not just use quotas on the filesystem? You can set the limit at something high, and then just use repquota to get your reports. No scripts to run or filesystems to scan.

Last edited by stickman; 08-05-2004 at 03:31 PM.
 
Old 08-06-2004, 02:09 PM   #4
kebabhead
LQ Newbie
 
Registered: Apr 2004
Location: west coast USA
Distribution: redhat 9, fedora core 2, Gentoo
Posts: 20

Original Poster
Rep: Reputation: 0
Lightbulb

Thanks very much for your replies!
Tinkster: your command does exactly what I was looking for, thanks! I knew there must be an answer for a common? question, but was surprised that I could'nt readily find it on google...
Stickman: Thanks, I've learned my lesson, next upgrade (soon) I will implement this...
 
Old 08-06-2004, 05:07 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by kebabhead
Tinkster: your command does exactly what I was looking for, thanks!
Glad you like my tiny awk-thing :)

Quote:
I knew there must be an answer for a common? question, but was surprised that I could'nt readily find it on google...
Next time round people can! :)

LQ and Google are a winning-team when it comes to
searching Linux related information... ;)


Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Filesystem Usage Question/Problem aukekim Fedora 1 08-25-2005 02:02 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
filesystem usage questions Menestrel Linux - Newbie 3 05-26-2004 11:35 AM
Where can I find a simple tutorial on quota (limit capacity of disk space of a user)? George2 Linux - Software 5 11-04-2003 08:56 AM
Restricting user disk usage ugenn Linux - General 1 05-13-2002 09:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration