#! /bin/sh

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

#	Copyright (c) 1984 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident	"$Header: dodisk.sh 1.7 90/01/26 $@(#)acct:dodisk.sh	1.7"
# 'perform disk accounting'
_dir=/usr/adm
_pickup=acct/nite
PATH=/usr/lib/acct:/bin:/usr/bin:/etc:
export PATH
while getopts o i
do
	case $i in
	o)	SLOW=1;;
	?)	echo "Usage: $0 [ -o ] [ filesystem ... ]"
		exit 1;;
	esac
done
shift `expr $OPTIND - 1`

cd ${_dir}
date

if [ "$SLOW" = "" ]
then
	if [ $# -lt 1 ]
	then
		#	diskusg only supports 4.2 type filesystems
		args=`sed -e '/^[ 	]*#/D' -e '/^[ 	]*$/D' /etc/fstab |
			while read dev fs fstype fsflags dummy
			do
				case ${fstype} in
				4.2 )
					echo $dev
					;;
				esac
			done`
	else
		args="$*"
	fi
	diskusg $args > dtmp
else
	if [ $# -lt 1 ]
	then
		args="/"
	else
		args="$*"
	fi
	for i in $args; do
		if [ ! -d $i ]
		then
			echo "$0: $i is not a directory -- ignored"
		else
			dir="$i $dir"
		fi
	done
	if [ "$dir" = "" ]
	then
		echo "$0: No data"
		> dtmp
	else
		find $dir -print | acctdusg > dtmp
	fi
fi

date
sort +0n +1 -o dtmp dtmp
acctdisk <dtmp >disktmp
chmod 644 disktmp
chown adm disktmp
mv disktmp ${_pickup}/disktacct
