xref: /onnv-gate/usr/src/cmd/acct/runacct.sh (revision 6558:b29051fff2ad)
10Sstevel@tonic-gate#!/sbin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*6558Ssv204098# Common Development and Distribution License (the "License").
7*6558Ssv204098# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#       Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
230Sstevel@tonic-gate#         All Rights Reserved
24*6558Ssv204098#	Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate#	Use is subject to license terms.
260Sstevel@tonic-gate
270Sstevel@tonic-gate
280Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
290Sstevel@tonic-gate#       "nitely accounting shell, should be run from cron (adm) at 4am"
300Sstevel@tonic-gate#	"does process, connect, disk, and fee accounting"
310Sstevel@tonic-gate#	"prepares command summaries"
320Sstevel@tonic-gate#	"shell is restartable and provides reasonable diagnostics"
330Sstevel@tonic-gate_adm=/var/adm
340Sstevel@tonic-gate_nite=/var/adm/acct/nite
350Sstevel@tonic-gate_sum=/var/adm/acct/sum
360Sstevel@tonic-gate_wtmpx=/var/adm/wtmpx
370Sstevel@tonic-gatePATH=/usr/lib/acct:/usr/bin:/usr/sbin
380Sstevel@tonic-gateexport PATH
390Sstevel@tonic-gate_statefile=${_nite}/statefile
400Sstevel@tonic-gate_active=${_nite}/active
410Sstevel@tonic-gate_lastdate=${_nite}/lastdate
420Sstevel@tonic-gate_date="`date +%m%d`"
430Sstevel@tonic-gate_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
440Sstevel@tonic-gate_MIN_BLKS=500
450Sstevel@tonic-gate
460Sstevel@tonic-gatecd ${_adm}
470Sstevel@tonic-gate#		"make sure that 2 crons weren't started, or leftover problems"
480Sstevel@tonic-gatedate  > ${_nite}/lock1
490Sstevel@tonic-gatechmod 400 ${_nite}/lock1
500Sstevel@tonic-gateln ${_nite}/lock1 ${_nite}/lock
510Sstevel@tonic-gateif test $? -ne 0; then
520Sstevel@tonic-gate	_lnkerr="\n\n*********** 2 CRONS or ACCT PROBLEMS***********\n\n\n"
530Sstevel@tonic-gate	(date ; echo "$_lnkerr" ) | logger -p daemon.err
540Sstevel@tonic-gate	echo "$_lnkerr" | mailx adm root
550Sstevel@tonic-gate	echo "ERROR: locks found, run aborted" >> ${_active}
560Sstevel@tonic-gate	rm -f ${_nite}/lock*
570Sstevel@tonic-gate	exit 1
580Sstevel@tonic-gatefi
590Sstevel@tonic-gate
600Sstevel@tonic-gate# Check to see if there is enough space in /var/adm to do nitely accounting
610Sstevel@tonic-gate#
620Sstevel@tonic-gate_blocks=`df $_adm | sed 's/.*://' | awk '{ print $1 }'`
630Sstevel@tonic-gateif [ "$_blocks" -le $_MIN_BLKS ];then
640Sstevel@tonic-gate	echo "runacct: Insufficient space in $_adm ($_blocks blks); \c"
650Sstevel@tonic-gate	echo "Terminating procedure"
660Sstevel@tonic-gate	( echo "runacct: Insufficient space in $_adm ($_blocks blks); \c"
670Sstevel@tonic-gate	echo "Terminating procedure" ) > /tmp/accounting_tmpfile
680Sstevel@tonic-gate	cat /tmp/accounting_tmpfile >> ${_active}
690Sstevel@tonic-gate        cat /tmp/accounting_tmpfile | logger -p daemon.err
700Sstevel@tonic-gate        mailx root adm < /tmp/accounting_tmpfile
710Sstevel@tonic-gate        rm /tmp/accounting_tmpfile
720Sstevel@tonic-gate
730Sstevel@tonic-gate	rm -f ${_nite}/lock*
740Sstevel@tonic-gate	exit 1
750Sstevel@tonic-gatefi
760Sstevel@tonic-gate
770Sstevel@tonic-gate
780Sstevel@tonic-gatecase $# in
790Sstevel@tonic-gate0)
800Sstevel@tonic-gate#	"as called by the cron each day"
810Sstevel@tonic-gate	if test ! -r ${_lastdate} ; then
820Sstevel@tonic-gate		echo "0000" > ${_lastdate}
830Sstevel@tonic-gate	fi
840Sstevel@tonic-gate	if test "${_date}" = "`cat ${_lastdate}`"; then
850Sstevel@tonic-gate		(date; echo "${_errormsg}") | logger -p daemon.err
860Sstevel@tonic-gate		echo "${_errormsg}" | mailx root adm
870Sstevel@tonic-gate		echo "ERROR: acctg already run for `date`: check ${_lastdate}" >> ${_active}
880Sstevel@tonic-gate		rm -f ${_nite}/lock*
890Sstevel@tonic-gate		mv ${_active} ${_active}${_date}
900Sstevel@tonic-gate		exit 1
910Sstevel@tonic-gate	fi
920Sstevel@tonic-gate	echo ${_date} > ${_lastdate}
930Sstevel@tonic-gate	echo "SETUP" > ${_statefile}
940Sstevel@tonic-gate	nulladm ${_active}
950Sstevel@tonic-gate	echo ${_date} > ${_active}    # debuging
960Sstevel@tonic-gate	echo "\n\n\n\n\n**********  SYSTEM ACCOUNTING STARTED `date`  **********\n\n\n\n\n" | logger -p daemon.notice
970Sstevel@tonic-gate	echo ${_date} > ${_active}    # debuging
980Sstevel@tonic-gate	;;
990Sstevel@tonic-gate
1000Sstevel@tonic-gate1)
1010Sstevel@tonic-gate#	"runacct MMDD  (date)  will restart at current state"
1020Sstevel@tonic-gate	_date=$1
1030Sstevel@tonic-gate	_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
1040Sstevel@tonic-gate	echo "restarting acctg for ${_date} at `cat ${_statefile}`" >> ${_active}
1050Sstevel@tonic-gate	echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
1060Sstevel@tonic-gate	;;
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate2)
1090Sstevel@tonic-gate#	"runacct MMDD STATE  restart at specified state"
1100Sstevel@tonic-gate	_date=$1
1110Sstevel@tonic-gate	_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
1120Sstevel@tonic-gate	echo "restarting acctg for ${_date} at $2" >> ${_active}
1130Sstevel@tonic-gate	echo "previous state was `cat ${_statefile}`" >> ${_active}
1140Sstevel@tonic-gate	echo "$2" > ${_statefile}
1150Sstevel@tonic-gate	echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
1160Sstevel@tonic-gate	;;
1170Sstevel@tonic-gate*)
1180Sstevel@tonic-gate	(date; echo "${_errormsg}") | logger -p daemon.err
1190Sstevel@tonic-gate	echo "${_errormsg}" | mailx root adm
1200Sstevel@tonic-gate	echo "ERROR: runacct called with invalid arguments" > ${_active}
1210Sstevel@tonic-gate	rm -f ${_nite}/lock*
1220Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
1230Sstevel@tonic-gate	exit 1
1240Sstevel@tonic-gate	;;
1250Sstevel@tonic-gateesac
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate#	"processing is broken down into seperate, restartable states"
1290Sstevel@tonic-gate#	"the statefile is updated at the end of each state so that the"
1300Sstevel@tonic-gate#	"next loop through the while statement switches to the next state"
1310Sstevel@tonic-gatewhile [ 1 ]
1320Sstevel@tonic-gatedo
1330Sstevel@tonic-gatecase "`cat ${_statefile}`" in
1340Sstevel@tonic-gateSETUP)
1350Sstevel@tonic-gate
1360Sstevel@tonic-gatecd ${_adm}
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate(date ; ls -l fee pacct* ${_wtmpx}* ) >> ${_active}
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate#	"switch current pacct file"
1410Sstevel@tonic-gateturnacct switch
1420Sstevel@tonic-gate_rc=$?
1430Sstevel@tonic-gateif test ${_rc} -ne 0; then
1440Sstevel@tonic-gate	(date ; echo "${_errormsg}" ) | logger -p daemon.err
1450Sstevel@tonic-gate	echo "${_errormsg}" | mailx root adm
1460Sstevel@tonic-gate	echo "ERROR: turnacct switch returned rc=${_rc}" >> ${_active}
1470Sstevel@tonic-gate	rm -f ${_nite}/lock*
1480Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
1490Sstevel@tonic-gate	exit 1
1500Sstevel@tonic-gatefi
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate#	" give pacct files unique names for easy restart "
1530Sstevel@tonic-gatefor _i in pacct?*
1540Sstevel@tonic-gatedo
1550Sstevel@tonic-gate	if [ "${_i}" = "pacct?*" ]
1560Sstevel@tonic-gate	then
1570Sstevel@tonic-gate		rm -f ${_nite}/lock*
1580Sstevel@tonic-gate		mv ${_active} ${_active}${_date}
1590Sstevel@tonic-gate		exit 1
1600Sstevel@tonic-gate	fi
1610Sstevel@tonic-gate	if test -r S${_i}.${_date} ; then
1620Sstevel@tonic-gate		 (date ; echo "${_errormsg}" ) | logger -p daemon.err
1630Sstevel@tonic-gate		echo "${_errormsg}" | mailx root adm
1640Sstevel@tonic-gate		echo "ERROR: S${_i}.${_date} already exists" >> ${_active}
1650Sstevel@tonic-gate		echo "file setups probably already run" >> ${_active}
1660Sstevel@tonic-gate		rm -f ${_nite}/lock*
1670Sstevel@tonic-gate		mv ${_active} ${_active}${_date}
1680Sstevel@tonic-gate		exit 1
1690Sstevel@tonic-gate	fi
1700Sstevel@tonic-gate	mv ${_i} S${_i}.${_date}
1710Sstevel@tonic-gatedone
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate#	"add current time on end"
1750Sstevel@tonic-gateif test -r ${_nite}/wtmpx.${_date} ; then
1760Sstevel@tonic-gate	(date ; echo "${_errormsg}" ) | logger -p daemon.err
1770Sstevel@tonic-gate	echo "${_errormsg}" | mailx root adm
1780Sstevel@tonic-gate	echo "ERROR: ${_nite}/wtmpx.${_date} already exists: run setup manually" > ${_active}
1790Sstevel@tonic-gate	rm -f ${_nite}/lock*
1800Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
1810Sstevel@tonic-gate	exit 1
1820Sstevel@tonic-gatefi
1830Sstevel@tonic-gateclosewtmp	# fudge a DEAD_PROCESS for /var/wtmpx
1840Sstevel@tonic-gatecp ${_wtmpx} ${_nite}/${_date}.wtmpx
1850Sstevel@tonic-gateacctwtmp "runacct" ${_nite}/${_date}.wtmpx
1860Sstevel@tonic-gatenulladm ${_wtmpx}
1870Sstevel@tonic-gateutmp2wtmp	# fudge active user from utmpx to wtmpx
1880Sstevel@tonic-gate
1890Sstevel@tonic-gateecho "files setups complete" >> ${_active}
1900Sstevel@tonic-gateecho "WTMPFIX" > ${_statefile}
1910Sstevel@tonic-gate;;
1920Sstevel@tonic-gate
1930Sstevel@tonic-gateWTMPFIX)
1940Sstevel@tonic-gate#	"verify the integrity of the wtmpx file"
1950Sstevel@tonic-gate#	"wtmpfix will automatically fix date changes"
1960Sstevel@tonic-gatecd ${_nite}
1970Sstevel@tonic-gatenulladm tmpwtmp wtmperror
1980Sstevel@tonic-gatewtmpfix < ${_date}.wtmpx > tmpwtmp 2>wtmperror
1990Sstevel@tonic-gateif test $? -ne 0 ; then
2000Sstevel@tonic-gate	(date ; echo "${_errormsg}") | mailx root adm
2010Sstevel@tonic-gate	echo "${_errormsg}" | logger -p daemon.err
2020Sstevel@tonic-gate	echo "ERROR: wtmpfix errors see ${_nite}/wtmperror${_date}" >> ${_active}
2030Sstevel@tonic-gate	rm -f ${_nite}/lock*
2040Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
2050Sstevel@tonic-gate	mv wtmperror wtmperror${_date}
2060Sstevel@tonic-gate	exit 1
2070Sstevel@tonic-gatefi
2080Sstevel@tonic-gate
2090Sstevel@tonic-gateecho "wtmpx processing complete" >> ${_active}
2100Sstevel@tonic-gateecho "CONNECT" > ${_statefile}
2110Sstevel@tonic-gate;;
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate
2140Sstevel@tonic-gateCONNECT)
2150Sstevel@tonic-gate#	"produce connect records"
2160Sstevel@tonic-gate#	"the lineuse and reboots files are used by prdaily"
2170Sstevel@tonic-gatecd ${_nite}
2180Sstevel@tonic-gatenulladm lineuse reboots log ctacct.${_date}
2190Sstevel@tonic-gateacctcon -l lineuse -o reboots < tmpwtmp  2> log > ctacct.${_date}
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate# if the following test is true, then pnpsplit complained about
2220Sstevel@tonic-gate# the year and holidays not being up to date.  This used to be
2230Sstevel@tonic-gate# a fatal error, but now it will continue to process the accounting.
2240Sstevel@tonic-gate#
2250Sstevel@tonic-gateif test -s log ; then
2260Sstevel@tonic-gate	(date ; cat ${_nite}/log) | mailx adm root
227*6558Ssv204098	echo "\n\n************ ACCT ERRORS : see  ${_nite}log********\n\n" | logger -p daemon.err
2280Sstevel@tonic-gate	cat ${_nite}/log >> ${_active}${_date}
2290Sstevel@tonic-gatefi
2300Sstevel@tonic-gate
2310Sstevel@tonic-gateecho "connect acctg complete" >> ${_active}
2320Sstevel@tonic-gateecho "PROCESS" > ${_statefile}
2330Sstevel@tonic-gate;;
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate
2360Sstevel@tonic-gatePROCESS)
2370Sstevel@tonic-gate#	"correlate Spacct and ptacct files by number"
2380Sstevel@tonic-gate#	"will not process Spacct file if corresponding ptacct exists"
2390Sstevel@tonic-gate#	"remove the ptacct file to rurun the Spacct file"
2400Sstevel@tonic-gate#	"if death occurs here, rerunacct should remove last ptacct file"
2410Sstevel@tonic-gate
2420Sstevel@tonic-gatecd ${_nite}
2430Sstevel@tonic-gatefor _Spacct in ${_adm}/Spacct*.${_date}
2440Sstevel@tonic-gatedo
2450Sstevel@tonic-gate	_ptacct=`basename ${_Spacct} | sed 's/Sp/pt/'`
2460Sstevel@tonic-gate	if test -s ${_ptacct}; then
2470Sstevel@tonic-gate		echo "WARNING: accounting already run for ${_Spacct}" \
2480Sstevel@tonic-gate			>> ${_active}
2490Sstevel@tonic-gate		echo "WARNING: remove ${_nite}/${_ptacct} to rerun" \
2500Sstevel@tonic-gate			>> ${_active}
2510Sstevel@tonic-gate	else
2520Sstevel@tonic-gate		nulladm ${_ptacct}
2530Sstevel@tonic-gate		acctprc < ${_Spacct} > ${_ptacct}
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate		echo "process acctg complete for ${_Spacct}" >> ${_active}
2560Sstevel@tonic-gate	fi
2570Sstevel@tonic-gatedone
2580Sstevel@tonic-gateecho "all process actg complete for ${_date}" >> ${_active}
2590Sstevel@tonic-gateecho "MERGE" > ${_statefile}
2600Sstevel@tonic-gate;;
2610Sstevel@tonic-gate
2620Sstevel@tonic-gate
2630Sstevel@tonic-gateMERGE)
2640Sstevel@tonic-gatecd ${_nite}
2650Sstevel@tonic-gate#	"merge ctacct and ptacct files together"
2660Sstevel@tonic-gateacctmerg ptacct*.${_date} < ctacct.${_date} > daytacct
2670Sstevel@tonic-gate
2680Sstevel@tonic-gateecho "tacct merge to create daytacct complete" >> ${_active}
2690Sstevel@tonic-gateecho "FEES" > ${_statefile}
2700Sstevel@tonic-gate;;
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate
2730Sstevel@tonic-gateFEES)
2740Sstevel@tonic-gatecd ${_nite}
2750Sstevel@tonic-gate#	"merge in fees"
2760Sstevel@tonic-gateif test -s ${_adm}/fee; then
2770Sstevel@tonic-gate	cp daytacct tmpdayt
2780Sstevel@tonic-gate	sort +0n +2 ${_adm}/fee | acctmerg -i | acctmerg tmpdayt  > daytacct
2790Sstevel@tonic-gate	echo "merged fees" >> ${_active}
2800Sstevel@tonic-gate	rm -f tmpdayt
2810Sstevel@tonic-gateelse
2820Sstevel@tonic-gate	echo "no fees" >> ${_active}
2830Sstevel@tonic-gatefi
2840Sstevel@tonic-gateecho "DISK" > ${_statefile}
2850Sstevel@tonic-gate;;
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate
2880Sstevel@tonic-gateDISK)
2890Sstevel@tonic-gatecd ${_nite}
2900Sstevel@tonic-gate#	"the last act of any disk acct procedure should be to mv its"
2910Sstevel@tonic-gate#	"entire output file to disktacct, where it will be picked up"
2920Sstevel@tonic-gateif test -r disktacct; then
2930Sstevel@tonic-gate	cp daytacct tmpdayt
2940Sstevel@tonic-gate	acctmerg disktacct  < tmpdayt > daytacct
2950Sstevel@tonic-gate	echo "merged disk records" >> ${_active}
2960Sstevel@tonic-gate	rm -f tmpdayt
2970Sstevel@tonic-gate	mv disktacct /tmp/disktacct.${_date}
2980Sstevel@tonic-gateelse
2990Sstevel@tonic-gate	echo "no disk records" >> ${_active}
3000Sstevel@tonic-gatefi
3010Sstevel@tonic-gateecho "MERGETACCT" > ${_statefile}
3020Sstevel@tonic-gate;;
3030Sstevel@tonic-gate
3040Sstevel@tonic-gateMERGETACCT)
3050Sstevel@tonic-gatecd ${_adm}/acct
3060Sstevel@tonic-gate#	"save each days tacct file in sum/tacct.${_date}"
3070Sstevel@tonic-gate#	"if sum/tacct gets corrupted or lost, could recreate easily"
3080Sstevel@tonic-gate#	"the monthly acctg procedure should remove all sum/tacct files"
3090Sstevel@tonic-gatecp nite/daytacct sum/tacct${_date}
3100Sstevel@tonic-gateif test ! -r sum/tacct; then
3110Sstevel@tonic-gate	echo "WARNING: recreating ${_adm}/sum/tacct " >> ${_active}
3120Sstevel@tonic-gate	nulladm sum/tacct
3130Sstevel@tonic-gatefi
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate#	"merge in todays tacct with the summary tacct"
3160Sstevel@tonic-gaterm -f sum/tacctprev
3170Sstevel@tonic-gatecp sum/tacct sum/tacctprev
3180Sstevel@tonic-gateacctmerg sum/tacctprev  < sum/tacct${_date} > sum/tacct
3190Sstevel@tonic-gate
3200Sstevel@tonic-gateecho "updated sum/tacct" >> ${_active}
3210Sstevel@tonic-gateecho "CMS" > ${_statefile}
3220Sstevel@tonic-gate;;
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate
3250Sstevel@tonic-gateCMS)
3260Sstevel@tonic-gatecd ${_adm}/acct
3270Sstevel@tonic-gate#	"do command summaries"
3280Sstevel@tonic-gatenulladm sum/daycms
3290Sstevel@tonic-gateif test ! -r sum/cms; then
3300Sstevel@tonic-gate	nulladm sum/cms
3310Sstevel@tonic-gate	echo "WARNING: recreating ${_adm}/sum/cms " >> ${_active}
3320Sstevel@tonic-gatefi
3330Sstevel@tonic-gatecp sum/cms sum/cmsprev
3340Sstevel@tonic-gateacctcms ${_adm}/Spacct*.${_date}  > sum/daycms
3350Sstevel@tonic-gateacctcms -s sum/daycms sum/cmsprev  > sum/cms
3360Sstevel@tonic-gateacctcms -a -s sum/daycms | sed -n 1,56p  > nite/daycms
3370Sstevel@tonic-gateacctcms -a -s sum/cms | sed -n 1,56p  > nite/cms
3380Sstevel@tonic-gatelastlogin
3390Sstevel@tonic-gateecho "command summaries complete" >> ${_active}
3400Sstevel@tonic-gateecho "USEREXIT" > ${_statefile}
3410Sstevel@tonic-gate;;
3420Sstevel@tonic-gate
3430Sstevel@tonic-gate
3440Sstevel@tonic-gateUSEREXIT)
3450Sstevel@tonic-gate#	"any installation dependant accounting programs should be run here"
3460Sstevel@tonic-gate[ -s /usr/lib/acct/runacct.local ] && /usr/lib/acct/runacct.local
3470Sstevel@tonic-gate
3480Sstevel@tonic-gateecho "CLEANUP" > ${_statefile}
3490Sstevel@tonic-gate;;
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate
3520Sstevel@tonic-gateCLEANUP)
3530Sstevel@tonic-gatecd ${_adm}/acct
3540Sstevel@tonic-gate#	" finally clear files; could be done next morning if desired"
3550Sstevel@tonic-gatenulladm ${_adm}/fee
3560Sstevel@tonic-gaterm -f ${_adm}/Spacct*.${_date}
3570Sstevel@tonic-gate#	"put reports onto a file"
3580Sstevel@tonic-gateprdaily >> sum/rprt${_date};
3590Sstevel@tonic-gaterm -f nite/lock*
3600Sstevel@tonic-gaterm -f nite/ptacct*.${_date} nite/ctacct.${_date}
3610Sstevel@tonic-gatemv -f nite/${_date}.wtmpx nite/owtmpx
3620Sstevel@tonic-gaterm -f nite/wtmperror${_date} nite/active${_date} nite/tmpwtmp
3630Sstevel@tonic-gateecho "system accounting completed at `date`" >> ${_active}
3640Sstevel@tonic-gateecho "********** SYSTEM ACCOUNTING COMPLETED `date` **********" | logger -p daemon.notice
3650Sstevel@tonic-gateecho "COMPLETE" > ${_statefile}
3660Sstevel@tonic-gateexit 0
3670Sstevel@tonic-gate;;
3680Sstevel@tonic-gate
3690Sstevel@tonic-gate*)
3700Sstevel@tonic-gate	(date;echo "${_errormsg}") | logger -p daemon.err
3710Sstevel@tonic-gate	echo "${_errormsg}" | mailx adm root
3720Sstevel@tonic-gate	echo "ERROR: invalid state, check ${_statefile}" >> active
3730Sstevel@tonic-gate	rm -f ${_nite}/lock*
3740Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
3750Sstevel@tonic-gate	exit 1
3760Sstevel@tonic-gate	;;
3770Sstevel@tonic-gateesac
3780Sstevel@tonic-gatedone
3790Sstevel@tonic-gate
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate#	" runacct is normally called with no arguments from the cron"
3820Sstevel@tonic-gate#	" it checks its own locks to make sure that 2 crons or previous"
3830Sstevel@tonic-gate#	" problems have not occured"
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate#	" runacct uses the statefile to record its progress"
3860Sstevel@tonic-gate#	" each state updates the statefile upon completion"
3870Sstevel@tonic-gate#	" then the next loop though the while picks up the new state"
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate#	" to restart this shell,  check the active file for diagnostics"
3900Sstevel@tonic-gate#	" fix up any corrupted data (ie. bad pacct or wtmpx files)"
3910Sstevel@tonic-gate#	" if runacct detected the error it removes the locks"
3920Sstevel@tonic-gate#	" remove the locks if necessary, otherwise runacct will complain"
3930Sstevel@tonic-gate#	" the lastdate file should be removed or changed"
3940Sstevel@tonic-gate#	" restart runacct at current state with:  runacct MMDD"
3950Sstevel@tonic-gate#	" to override the statefile: runacct MMDD STATE"
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate#	" if runacct has been executed after the latest failure"
3990Sstevel@tonic-gate#	" ie. it ran ok today but failed yesterday"
4000Sstevel@tonic-gate#	" the statefile will not be correct"
4010Sstevel@tonic-gate#	" check the active files and restart properly"
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate#	" if runacct failed in the PROCESS state, remove the last"
4040Sstevel@tonic-gate#	" ptacct file because it may not be complete"
4050Sstevel@tonic-gate
4060Sstevel@tonic-gate#	" if shell has failed several days, do SETUP manually"
4070Sstevel@tonic-gate#	" then rerun runacct once for each day failed"
4080Sstevel@tonic-gate#	" could use fwtmp here to split up wtmpx file correctly"
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate#	" normally not a good idea to restart the SETUP state"
4110Sstevel@tonic-gate#	" should be done manually, or just cleanup first"
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate#	" FILE USAGE:	all files in /var/adm/acct/nite unless specified"
4150Sstevel@tonic-gate
4160Sstevel@tonic-gate#	" statefile	records progess of runacct"
4170Sstevel@tonic-gate#	" lastdate	last day runacct ran in date +%m%d format"
4180Sstevel@tonic-gate#	" lock lock1	controls serial use of runacct"
4190Sstevel@tonic-gate#	" active	place for all descriptive and error messages"
4200Sstevel@tonic-gate#	" fd2log	fd2 output for runacct ( see cron entry ) "
4210Sstevel@tonic-gate#	" MMDD.wtmpx    owtmpx yesterdays wtmpx file"
4220Sstevel@tonic-gate#	" tmpwtmp	yesterdays wtmp corrected by wtmpfix"
4230Sstevel@tonic-gate#	" wtmperror	place for wtmpfix error messages"
4240Sstevel@tonic-gate#	" lineuse	lineusage report used in prdaily"
4250Sstevel@tonic-gate#	" reboots	reboots report used in prdaily"
4260Sstevel@tonic-gate#	" log		place for error messages from acctcon1"
4270Sstevel@tonic-gate#	" ctacct.MMDD	connect tacct records for MMDD"
4280Sstevel@tonic-gate#	" ptacct.n.MMDD	process tacct records n files for MMDD"
4290Sstevel@tonic-gate#	" daytacct	total tacct records for this days accounting"
4300Sstevel@tonic-gate#	" disktacct	disk tacct records produced by disk shell"
4310Sstevel@tonic-gate#	" daycms	ascii daily command summary used by prdaily"
4320Sstevel@tonic-gate#	" cms		acsii total command summary used by prdaily"
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate#	" following files in /var/adm directory"
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate#	" fee		output from chargefee program"
4370Sstevel@tonic-gate#	" pacct		active pacct file"
4380Sstevel@tonic-gate#	" pacctn	switched pacct files"
4390Sstevel@tonic-gate#	" Spacctn.MMDD	pacct files for MMDD after SETUP state"
4400Sstevel@tonic-gate#	" wtmpx		active wtmpx file"
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate#	" following files in /var/adm/acct/sum"
4430Sstevel@tonic-gate
4440Sstevel@tonic-gate#	" loginlog	output of lastlogin used in prdaily"
4450Sstevel@tonic-gate#	" tacct		total tacct file for current fiscal"
4460Sstevel@tonic-gate#	" tacct.MMDD	tacct file for day MMDD"
4470Sstevel@tonic-gate#	" cms		total cms file for current fiscal"
4480Sstevel@tonic-gate#	" rprt.MMDD	output of prdaily program"
4490Sstevel@tonic-gate#	" MMDD.wtmpx	saved copy of wtmpx for MMDD"
4500Sstevel@tonic-gate#	" pacct.MMDD	concatenated version of all pacct files for MMDD"
4510Sstevel@tonic-gate#	" cmsprev	total cms file without latest update"
4520Sstevel@tonic-gate#	" tacctprev	total tacct file without latest update"
4530Sstevel@tonic-gate#	" daycms	cms files for todays usage"
454