xref: /titanic_44/usr/src/cmd/acct/dodisk.sh (revision 4496171313bed39e96f21bc2f9faf2868e267ae3)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
29#	  All Rights Reserved
30
31
32#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.13	*/
33# 'perform disk accounting'
34PATH=:/usr/lib/acct:/usr/bin:/usr/sbin
35export PATH
36if [ -f  /usr/bin/uts -a /usr/bin/uts ]
37then
38	format="dev mnt type comment"
39else
40	format="special dev mnt fstype fsckpass automnt mntflags"
41fi
42_dir=/var/adm
43_pickup=acct/nite
44set -- `getopt o $*`
45if [ $? -ne 0 ]
46then
47	echo "Usage: $0 [ -o ] [ filesystem ... ]" >&2
48	exit 1
49fi
50for i in $*; do
51	case $i in
52	-o)	SLOW=1; shift;;
53	--)	shift; break;;
54	esac
55done
56
57cd ${_dir}
58
59if [ "$SLOW" = "" ]
60then
61	if [ $# -lt 1 ]
62	then
63		if [ -f  /usr/bin/uts -a /usr/bin/uts ]
64		then
65			DEVLIST=/etc/checklist
66		else
67			DEVLIST=/etc/vfstab
68		fi
69		while :
70		do
71			if read $format
72		       	then
73				if [ -z "$special" ]
74				then
75					continue
76				elif [ `expr $special : '\(.\)'` = \# ]
77		       		then
78		               		continue
79		        	fi
80				if [ "$fsckpass" = "-" ]
81				then
82					continue
83				fi
84				if [ $fstype != ufs ] && [ $fstype != vxfs ]
85				then
86					continue
87				fi
88
89				# Make sure FS is mounted
90				if egrep -s "^${special}[ 	]+${mnt}[ 	]" /etc/mnttab
91				then
92					find $mnt -mount -print | \
93					acctdusg > \
94					    `echo $dev | sed s-/-_-g`.dtmp &
95				fi
96			else
97				wait
98				break
99			fi
100		done < $DEVLIST
101		if [ "`echo *.dtmp`" != "*.dtmp" ]
102		then
103			awk -e '
104	{tot[$1] += $3; if (name[$1] == "") name[$1] = "" $2}
105END	{for (i in tot) printf "%d\t%s\t%d\n", i, name[i], tot[i]}' *.dtmp > dtmp
106			rm -f *.dtmp
107		else
108			> dtmp
109		fi
110	else
111		find $* -mount -print | acctdusg > dtmp
112	fi
113else
114	if [ $# -lt 1 ]
115	then
116		args="/"
117	else
118		args="$*"
119	fi
120	for i in $args; do
121		if [ ! -d $i ]
122		then
123			echo "$0: $i is not a directory -- ignored" >&2
124		else
125			dir="$i $dir"
126		fi
127	done
128	if [ "$dir" = "" ]
129	then
130		echo "$0: No data" >&2
131		> dtmp
132	else
133		find $dir -print | acctdusg > dtmp
134	fi
135fi
136
137sort +0n +1 dtmp | acctdisk > ${_pickup}/disktacct
138chmod 644 ${_pickup}/disktacct
139chown adm ${_pickup}/disktacct
140