8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / acct / dodisk.sh
blobcea3161a0f9bc09206ddf5adedff011992cc8892
1 #!/sbin/sh
3 # CDDL HEADER START
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.
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.
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]
21 # CDDL HEADER END
24 # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
28 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
29 # All Rights Reserved
32 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.13 */
33 # 'perform disk accounting'
34 PATH=:/usr/lib/acct:/usr/bin:/usr/sbin
35 export PATH
36 if [ -f /usr/bin/uts -a /usr/bin/uts ]
37 then
38 format="dev mnt type comment"
39 else
40 format="special dev mnt fstype fsckpass automnt mntflags"
42 _dir=/var/adm
43 _pickup=acct/nite
44 set -- `getopt o $*`
45 if [ $? -ne 0 ]
46 then
47 echo "Usage: $0 [ -o ] [ filesystem ... ]" >&2
48 exit 1
50 for i in $*; do
51 case $i in
52 -o) SLOW=1; shift;;
53 --) shift; break;;
54 esac
55 done
57 cd ${_dir}
59 if [ "$SLOW" = "" ]
60 then
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
69 while :
71 if read $format
72 then
73 if [ -z "$special" ]
74 then
75 continue
76 elif [ `expr $special : '\(.\)'` = \# ]
77 then
78 continue
80 if [ "$fsckpass" = "-" ]
81 then
82 continue
84 if [ $fstype != ufs ] && [ $fstype != vxfs ]
85 then
86 continue
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 &
96 else
97 wait
98 break
100 done < $DEVLIST
101 if [ "`echo *.dtmp`" != "*.dtmp" ]
102 then
103 awk -e '
104 {tot[$1] += $3; if (name[$1] == "") name[$1] = "" $2}
105 END {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
110 else
111 find $* -mount -print | acctdusg > dtmp
113 else
114 if [ $# -lt 1 ]
115 then
116 args="/"
117 else
118 args="$*"
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"
127 done
128 if [ "$dir" = "" ]
129 then
130 echo "$0: No data" >&2
131 > dtmp
132 else
133 find $dir -print | acctdusg > dtmp
137 sort +0n +1 dtmp | acctdisk > ${_pickup}/disktacct
138 chmod 644 ${_pickup}/disktacct
139 chown adm ${_pickup}/disktacct