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