xref: /titanic_51/usr/src/cmd/acct/ckpacct.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24#	  All Rights Reserved
25
26#
27# Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
28# Use is subject to license terms.
29#
30
31#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
32#       periodically check the size of /var/adm/pacct
33#       if over $1 blocks (default: maxi 200, mini 500), execute
34#	turnacct switch
35
36_adm=/var/adm
37PATH=/usr/lib/acct:/usr/bin:/usr/sbin
38trap "rm -f /var/adm/cklock*; exit 0" 0 1 2 3 9 15
39export PATH
40
41if [ -f uts -a uts ]
42then
43	_max=${1-200}
44else
45	_max=${1-500}
46fi
47_MIN_BLKS=500
48cd /var/adm
49
50#	set up lock files to prevent simultaneous checking
51
52cp /dev/null cklock
53chmod 400 cklock
54ln cklock cklock1
55if test $? -ne 0 ; then exit 1; fi
56
57#	If there are less than $_MIN_BLKS free blocks left on the /var/adm
58#	file system, turn off the accounting (unless things improve
59#	the accounting wouldn't run anyway).  If something has
60#	returned the file system space, restart accounting.  This
61#	feature relies on the fact that ckpacct is kicked off by the
62#	cron at least once per hour.
63
64
65_blocks=`df $_adm | sed 's/.*://' | awk '{ print $1 }'`
66
67if [ "$_blocks" -lt $_MIN_BLKS   -a  -f /tmp/acctoff ];then
68	echo "ckpacct: $_adm still low on space ($_blocks blks); \c"
69	echo "acctg still off"
70	( echo "ckpacct: $_adm still low on space ($_blocks blks); \c"
71	echo "acctg still off" ) | mailx root adm
72	exit 1
73elif [ "$_blocks" -lt $_MIN_BLKS ];then
74	echo "ckpacct: $_adm too low on space ($_blocks blks); \c"
75	echo "turning acctg off"
76	( echo "ckpacct: $_adm too low on space ($_blocks blks); \c"
77	echo "turning acctg off" ) | mailx root adm
78	nulladm /tmp/acctoff
79	turnacct off
80	exit 1
81elif [ -f /tmp/acctoff ];then
82	echo "ckpacct: $_adm free space restored; turning acctg on"
83	echo "ckpacct: $_adm free space restored; turning acctg on" | \
84		mailx root adm
85	rm /tmp/acctoff
86	turnacct on
87fi
88
89_cursize="`du -s pacct | sed 's/	.*//'`"
90if [ "${_max}" -lt "${_cursize}" ]; then
91	turnacct switch
92fi
93