finding total "disk used" per user

finding total "disk used" per user

Post by Alan Yasutovi » Wed, 26 Jan 1994 03:26:09



        Anyone got any ginchy scripts to get a daily or weekly list
        of disk used per user?

        It is required of me.

        I'm writing a script but there may be something out there
        already.

--
        Alan Yasutovich
        "inquiring  (and nosey) minds WANT TO KNOW!!!"
        I can remember when "safe sex" meant having a padded headboard!!
        Tick Tock.....Tick Tock......Tick Tock .....Tick Tock......

 
 
 

finding total "disk used" per user

Post by Daniel Len Schal » Thu, 27 Jan 1994 00:28:19




> >       Anyone got any ginchy scripts to get a daily or weekly list
> >       of disk used per user?
> use   du -s $HOME
> For instance, you might start (by crontab) every Sunday morning
> something which essentially does
> echo "`date` `du -s $HOME`" >> $HOME.du.log

No mention of UNIX flavor is given, but if you have the quot command
try it (the f and v options provide a nice report).
The problem with du is that it doesn't distinguish between users, just dumps
the directory totals, so data can be incorrectly attributed to other
users by storing it in their writable directories.  

If you have quota's, you should be able to generate a report
using repquota.  Most accounting packages also have disk
reporting facilities:

/usr/lib/acct/diskusg /dev/id001h

Danny

 
 
 

finding total "disk used" per user

Post by Brian E. Galle » Thu, 27 Jan 1994 03:29:01


Here is a script I use on a nightly basis.  Caveat:  if you are going
to run this, watch out for function calls and file usages!  This is
part of a *large* group of administrative scripts that I maintain.
=========================================================================
#! /bin/ksh

HOME=/usr/adm/quota
TEMP1=$HOME/temp1
TEMP2=$HOME/temp2
TEMP3=$HOME/temp3
TEMP4=$HOME/diskusage
STATUS=$HOME/status
QUOTA=$HOME/quotas
LOCKFILE=/tmp/quota.LCK
export LOCKFILE

# If you change these, don't forget to change them within the awk script at the
#end of this file!
HARD=$HOME/hard
SOFT=$HOME/soft

unalias rm

trap "if [ -f "$LOCKFILE" ];then rm -f $LOCKFILE;fi;exit" EXIT 2 3 12

while [ -f $LOCKFILE ];do
        sleep 1
done;

touch $LOCKFILE

rm -f $TEMP1 $TEMP2 $TEMP3 $TEMP4 $STATUS

#This is the list of file systems we want to check for quota

FS="/ua /ub /uc /ud /ue /uf /ug /uh /ui /uj /uk /ul"

#clean up from last execution of checkquota
for FILE in $SOFT $HARD ; do
exec 9< $FILE
while read JUNK <&9 ; do
        NAME=`echo "$JUNK" | awk '{print $1}'`
        DIR=`grep "^$NAME:" /etc/passwd | awk 'BEGIN{FS=":"}{print $6}'`
        if [ -z "$DIR" ] ; then
                echo "Couldn't find home dir for $NAME!"
                continue
        fi
        if [ ! -f $DIR/.quota ] ; then
                echo "Couldn't find $DIR/.quota for name!"
                continue
        fi
        rm -f $DIR/.quota
done
done

#Create two files: TEMP1 TEMP2.  TEMP1 contains a listing of the sizes of
#all the directories.  TEMP2 contains a listing of directories and their
#owners.

for d in $FS;do
        du -s $d/* | awk '{printf "%-25s %s\n",$2,$1}' >> $TEMP1
        ls -l $d | awk '{printf "%-21s %s\n",$9,$3}' > $TEMP3
        (exec < $TEMP3
        while read JUNK;do
                if [ -n "$JUNK" ]
                then
                        echo "$d/$JUNK" >> $TEMP2
                fi
        done) done

#Sort TEMP1

test -z "$DEBUG" || echo about to mess with temp3
sort < $TEMP1 > $TEMP3
mv $TEMP3 $TEMP1

#Sort TEMP2

sort < $TEMP2 > $TEMP3
mv $TEMP3 $TEMP2

test -z "$DEBUG" || echo Creating temp3
#Create TEMP3 from TEMP1 and TEMP2.  Temp 3 contains a list of users
#and sizes

join -o 2.2 1.2 $TEMP1 $TEMP2 | sort > $TEMP3
rm -f $TEMP1 $TEMP2

#This loop creates TEMP4, which is the same as TEMP3, except that
#multiple sizes owned by the same user get added together.

USER=
SUM=
test -z "$DEBUG" || echo Creating temp4
exec 9< $TEMP3
while read JUNK <&9 ; do
        NEWUSER=`echo $JUNK | awk '{print $1}'`
        COUNT=`echo $JUNK | awk '{print $2}'`
        if [ "$USER" != "$NEWUSER" ]
        then
                echo "$USER $SUM" >> $TEMP4
                USER="$NEWUSER"
                SUM="$COUNT"
        else
                SUM=`expr $SUM + $COUNT`
        fi
done

#flush the last data read!
echo "$USER $SUM" >> $TEMP4

#Remove the leading empty line from TEMP4

tail +2 $TEMP4 > $STATUS
mv $STATUS $TEMP4

test -z "$DEBUG" || echo About to joing temp4 and quota

#Create the quota status file

join -o 1.1 1.2 2.3 2.5 $TEMP4 $QUOTA > $STATUS

SHELL=/bin/sh
export SHELL
unset ENV

#Create the hard and soft files.  The files list accounts which have exceeded
#their hard and soft quota limits respectively.
rm -f $TEMP2 $TEMP1
test -f $HARD && mv $HARD $TEMP1
test -f $SOFT && mv $SOFT $TEMP2
DATE=`date +"%y %j"`
exec 9< $STATUS
while read JUNK <&9 ;do
        if [ -n "$JUNK" ];then
                NAME=`echo "$JUNK" | awk '{print $1}'`
                USED=`echo "$JUNK" | awk '{print $2}'`
                soft=`echo "$JUNK" | awk '{print $3}'`
                hard=`echo "$JUNK" | awk '{print $4}'`
                if [ "$USED" -gt "$hard" ];then
                        echo $NAME $((USED-hard)) $DATE >> $HARD
                elif [ "$USED" -gt "$soft" ];then
                        echo $NAME $((USED-soft)) $DATE >> $SOFT
                fi
        fi
done

touch $TEMP1 $HARD $SOFT
exec 9< $TEMP1
test -z "$DEBUG" || echo deleting temp3 once
rm -f $TEMP3
while read JUNK <&9 ; do
        if [ -n "$JUNK" ];then
                NAME=`echo "$JUNK" | awk '{print $1}'`
                if [ -n "`grep $NAME $HARD`" ];then
                        echo "$JUNK" >> $TEMP3
                fi
        fi
done

exec 9< $HARD
while read JUNK <&9 ; do
        if [ -n "$JUNK" ];then
                NAME=`echo "$JUNK" | awk '{print $1}'`
                if [ -z "`grep $NAME $TEMP1`" ];then
                        echo "$JUNK" >> $TEMP3
                fi
        fi
done
touch $TEMP3
test -z "$DEBUG" || echo moving temp3 to hard
mv $TEMP3 $HARD

touch $TEMP2
exec 9< $TEMP2
while read JUNK <&9 ; do
        if [ -n "$JUNK" ];then
                NAME=`echo "$JUNK" | awk '{print $1}'`
                if [ -n "`grep $NAME $SOFT`" ];then
                        test -z "$DEBUG" || echo in temp2 loop
                        echo "$JUNK" >> $TEMP3
                fi
        fi
done

test -z "$DEBUG" || echo going in soft loop with temp3
exec < $SOFT
while read JUNK <&9 ; do
        if [ -n "$JUNK" ];then
                NAME=`echo "$JUNK" | awk '{print $1}'`
                if [ -z "`grep $NAME $TEMP2`" ];then
                        echo "$JUNK" >> $TEMP3
                fi
        fi
done
touch $TEMP3
test -z "$DEBUG" || echo moving temp3 to soft
mv $TEMP3 $SOFT

THISYEAR=`date +%y`
THISDAY=`date +%j`
export THISYEAR THISDAY

(exec < $SOFT
while read JUNK;do
        if [ -n "$JUNK" ];then
                YEAR=`echo "$JUNK" | awk '{print $3}'`
                DAY=`echo "$JUNK" | awk '{print $4}'`
                NAME=`echo "$JUNK" | awk '{print $1}'`
                DIR=`grep "^$NAME:" /etc/passwd | awk 'BEGIN {FS=":"}{print $6}'`
                if [ $DAY -gt $THISDAY ];then
                        COUNT=`expr 365 + $THISDAY - $DAY`
                        YEAR=`expr $YEAR + 1`
                else
                        COUNT=`expr $THISDAY - $DAY`
                fi
                if [ $THISYEAR -gt $YEAR ];then
                        COUNT=`expr $COUNT + 365`
                fi
                C2=`expr 14 - $COUNT`
                if [ $COUNT -gt 14 ];then
                        cat > $DIR/.account_locked <<END1
You have exceeded your soft quota limit for more than two weeks!
Contact Brian Gallew (x8557) to arrange for some files to be deleted
and to have your account unlocked.
END1
                chmod 644 $DIR/.account_locked
                else
                cat > $DIR/.quota <<END2
You have exceeded your soft quota limit.  You have $C2 day(s)
remaining in which to delete sufficient files or contact Kurt
Massarelli (x3862) to arrange for an increase in quota,
END2
                chmod 644 $DIR/.quota
                fi
        fi
done)

(exec < $HARD
while read JUNK;do
        if [ -n "$JUNK" ];then
                YEAR=`echo "$JUNK" | awk '{print $3}'`
                DAY=`echo "$JUNK" | awk '{print $4}'`
                NAME=`echo "$JUNK" | awk '{print $1}'`
                DIR=`grep "^$NAME:" /etc/passwd | awk 'BEGIN {FS=":"}{print $6}'`
                if [ $DAY -gt $THISDAY ];then
                        COUNT=`expr 365 + $THISDAY - $DAY`
                        YEAR=`expr $YEAR + 1`
                else
                        COUNT=`expr $THISDAY - $DAY`
                fi
                if [ $THISYEAR -gt $YEAR ];then
                        COUNT=`expr $COUNT + 365`
                fi
                C2=`expr 1 - $COUNT`
                if [ $COUNT -gt 1 ];then
                        cat > $DIR/.account_locked <<END1
You have exceeded your hard quota limit for more than two days!
Contact Brian Gallew (x8557) to arrange for some files to be deleted
and to have your account unlocked.
END1
                chmod 644 $DIR/.account_locked
                else
                cat > $DIR/.quota <<END2
You have exceeded your hard quota limit.  You have $C2 day(s)
remaining in which to delete sufficient files or contact Kurt
Massarelli (x3862) to arrange for an increase in quota,
END2
                chmod 644 $DIR/.quota
                fi
        fi
done)

chmod 644 $HOME/*

rm -f $TEMP1 $TEMP2 $LOCKFILE
=========================================================================

                                  -Brian

=========================================================================
| MS-DOS --> MicroSoft-Denial Of Service                             |
=========================================================================

 
 
 

finding total "disk used" per user

Post by Joe Emenak » Thu, 27 Jan 1994 11:03:15



>    Anyone got any ginchy scripts to get a daily or weekly list
>    of disk used per user?

>    It is required of me.

>    I'm writing a script but there may be something out there
>    already.

Well, they're probably some administration script on your system that does
that, but I don't use them.

One thing you CAN do is use quotas. If you don't want to enforce any
quotas, just set everyone's quota to something astronomical that will
never get triggered. Then, use "quotacheck" to compile the current
usages and then use "repquota" to get a list of who's using how much.

 
 
 

finding total "disk used" per user

Post by Part » Thu, 27 Jan 1994 21:47:28



>    Anyone got any ginchy scripts to get a daily or weekly list
>    of disk used per user?

I would do something along the lines of

  du -s * /users

where /users is the directory which contains all the home directories
(/users/username being the home directory of user username).

What I do is, I then sort this by size and store only those with the
largest sizes.

--

EDV-Zentrum, Universitaet fuer Bodenkultur
Nussdorfer Laende 11                      Please correct me, if I am wrong!
A-1190 Wien, Austria (Europe)             Make love, not flame wars.  :-)

 
 
 

finding total "disk used" per user

Post by Mark Newt » Mon, 31 Jan 1994 17:47:05



 > >      Anyone got any ginchy scripts to get a daily or weekly list
 > >      of disk used per user?

 > I would do something along the lines of

 >   du -s * /users

 > where /users is the directory which contains all the home directories
 > (/users/username being the home directory of user username).

 > What I do is, I then sort this by size and store only those with the
 > largest sizes.

If you have a Berkeley-based system with quotas enabled, you can also
use the "repquota" command to find out how much space each user is using.

The advantage of that is that with the -a option, it'll show total disk
space on all filesystems (not just the home directory tree) *very quickly*.

Of course, you need to run quotacheck regularly to keep its picture of
the world up-to-date, but you'll be doing that anyway if you have quotas
enabled.

   - mark
--
--------------------------------------------------------------------

     but it hurt when I walked.                          Mark Newton
----- Voice: +61-8-3735575 --------------- Data: +61-8-3736006 -----

 
 
 

1. USING SENDMAIL "user@domain.com" vs. "user@host.domain.com"

I am currently running ESMTP Sendmail 8.8.7/8.8.7.

With my current configuration in order for sendmail to file incoming
messages to the correct mailbox the message must be sent to

How do I set up sendmail  to receive e-mail messages that where sent to

For example:
Right now to e-mail me you could send the message to


I do currently have an MX resource record in my DNS that sets the linux01
host to be the mail exchanger for the pcscs domain.

thanks in advance

Charles Wilkins

2. Access linux parition from windows

3. GETSERVBYNAME()????????????????????"""""""""""""

4. Server Error

5. E250 internal disks: "Sun" disk vs "generic" Seagate disk

6. Letting add_install_client modify /etc/hosts

7. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

8. HOW-TO : undelete linux files (ext2fs/debugfs)

9. Using "if" in "ksh" to change "for loop" values....

10. Mac "find" performs far better than Unix O(n^2) "find"

11. STARTX: "No Screens Found"/"Can't find Display"

12. Unix/linux "installation user" vs MS Windows "installation user".

13. userdel : "user" is in use, but "user" isn't logged