xref: /illumos-gate/usr/src/cmd/acct/runacct.sh (revision 5068e65b)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*5068e65bSsv# Common Development and Distribution License (the "License").
7*5068e65bSsv# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#       Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
237c478bd9Sstevel@tonic-gate#         All Rights Reserved
24*5068e65bSsv#	Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate#	Use is subject to license terms.
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
297c478bd9Sstevel@tonic-gate#       "nitely accounting shell, should be run from cron (adm) at 4am"
307c478bd9Sstevel@tonic-gate#	"does process, connect, disk, and fee accounting"
317c478bd9Sstevel@tonic-gate#	"prepares command summaries"
327c478bd9Sstevel@tonic-gate#	"shell is restartable and provides reasonable diagnostics"
337c478bd9Sstevel@tonic-gate_adm=/var/adm
347c478bd9Sstevel@tonic-gate_nite=/var/adm/acct/nite
357c478bd9Sstevel@tonic-gate_sum=/var/adm/acct/sum
367c478bd9Sstevel@tonic-gate_wtmpx=/var/adm/wtmpx
377c478bd9Sstevel@tonic-gatePATH=/usr/lib/acct:/usr/bin:/usr/sbin
387c478bd9Sstevel@tonic-gateexport PATH
397c478bd9Sstevel@tonic-gate_statefile=${_nite}/statefile
407c478bd9Sstevel@tonic-gate_active=${_nite}/active
417c478bd9Sstevel@tonic-gate_lastdate=${_nite}/lastdate
427c478bd9Sstevel@tonic-gate_date="`date +%m%d`"
437c478bd9Sstevel@tonic-gate_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
447c478bd9Sstevel@tonic-gate_MIN_BLKS=500
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gatecd ${_adm}
477c478bd9Sstevel@tonic-gate#		"make sure that 2 crons weren't started, or leftover problems"
487c478bd9Sstevel@tonic-gatedate  > ${_nite}/lock1
497c478bd9Sstevel@tonic-gatechmod 400 ${_nite}/lock1
507c478bd9Sstevel@tonic-gateln ${_nite}/lock1 ${_nite}/lock
517c478bd9Sstevel@tonic-gateif test $? -ne 0; then
527c478bd9Sstevel@tonic-gate	_lnkerr="\n\n*********** 2 CRONS or ACCT PROBLEMS***********\n\n\n"
537c478bd9Sstevel@tonic-gate	(date ; echo "$_lnkerr" ) | logger -p daemon.err
547c478bd9Sstevel@tonic-gate	echo "$_lnkerr" | mailx adm root
557c478bd9Sstevel@tonic-gate	echo "ERROR: locks found, run aborted" >> ${_active}
567c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
577c478bd9Sstevel@tonic-gate	exit 1
587c478bd9Sstevel@tonic-gatefi
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate# Check to see if there is enough space in /var/adm to do nitely accounting
617c478bd9Sstevel@tonic-gate#
627c478bd9Sstevel@tonic-gate_blocks=`df $_adm | sed 's/.*://' | awk '{ print $1 }'`
637c478bd9Sstevel@tonic-gateif [ "$_blocks" -le $_MIN_BLKS ];then
647c478bd9Sstevel@tonic-gate	echo "runacct: Insufficient space in $_adm ($_blocks blks); \c"
657c478bd9Sstevel@tonic-gate	echo "Terminating procedure"
667c478bd9Sstevel@tonic-gate	( echo "runacct: Insufficient space in $_adm ($_blocks blks); \c"
677c478bd9Sstevel@tonic-gate	echo "Terminating procedure" ) > /tmp/accounting_tmpfile
687c478bd9Sstevel@tonic-gate	cat /tmp/accounting_tmpfile >> ${_active}
697c478bd9Sstevel@tonic-gate        cat /tmp/accounting_tmpfile | logger -p daemon.err
707c478bd9Sstevel@tonic-gate        mailx root adm < /tmp/accounting_tmpfile
717c478bd9Sstevel@tonic-gate        rm /tmp/accounting_tmpfile
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
747c478bd9Sstevel@tonic-gate	exit 1
757c478bd9Sstevel@tonic-gatefi
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gatecase $# in
797c478bd9Sstevel@tonic-gate0)
807c478bd9Sstevel@tonic-gate#	"as called by the cron each day"
817c478bd9Sstevel@tonic-gate	if test ! -r ${_lastdate} ; then
827c478bd9Sstevel@tonic-gate		echo "0000" > ${_lastdate}
837c478bd9Sstevel@tonic-gate	fi
847c478bd9Sstevel@tonic-gate	if test "${_date}" = "`cat ${_lastdate}`"; then
857c478bd9Sstevel@tonic-gate		(date; echo "${_errormsg}") | logger -p daemon.err
867c478bd9Sstevel@tonic-gate		echo "${_errormsg}" | mailx root adm
877c478bd9Sstevel@tonic-gate		echo "ERROR: acctg already run for `date`: check ${_lastdate}" >> ${_active}
887c478bd9Sstevel@tonic-gate		rm -f ${_nite}/lock*
897c478bd9Sstevel@tonic-gate		mv ${_active} ${_active}${_date}
907c478bd9Sstevel@tonic-gate		exit 1
917c478bd9Sstevel@tonic-gate	fi
927c478bd9Sstevel@tonic-gate	echo ${_date} > ${_lastdate}
937c478bd9Sstevel@tonic-gate	echo "SETUP" > ${_statefile}
947c478bd9Sstevel@tonic-gate	nulladm ${_active}
957c478bd9Sstevel@tonic-gate	echo ${_date} > ${_active}    # debuging
967c478bd9Sstevel@tonic-gate	echo "\n\n\n\n\n**********  SYSTEM ACCOUNTING STARTED `date`  **********\n\n\n\n\n" | logger -p daemon.notice
977c478bd9Sstevel@tonic-gate	echo ${_date} > ${_active}    # debuging
987c478bd9Sstevel@tonic-gate	;;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate1)
1017c478bd9Sstevel@tonic-gate#	"runacct MMDD  (date)  will restart at current state"
1027c478bd9Sstevel@tonic-gate	_date=$1
1037c478bd9Sstevel@tonic-gate	_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
1047c478bd9Sstevel@tonic-gate	echo "restarting acctg for ${_date} at `cat ${_statefile}`" >> ${_active}
1057c478bd9Sstevel@tonic-gate	echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
1067c478bd9Sstevel@tonic-gate	;;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate2)
1097c478bd9Sstevel@tonic-gate#	"runacct MMDD STATE  restart at specified state"
1107c478bd9Sstevel@tonic-gate	_date=$1
1117c478bd9Sstevel@tonic-gate	_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
1127c478bd9Sstevel@tonic-gate	echo "restarting acctg for ${_date} at $2" >> ${_active}
1137c478bd9Sstevel@tonic-gate	echo "previous state was `cat ${_statefile}`" >> ${_active}
1147c478bd9Sstevel@tonic-gate	echo "$2" > ${_statefile}
1157c478bd9Sstevel@tonic-gate	echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
1167c478bd9Sstevel@tonic-gate	;;
1177c478bd9Sstevel@tonic-gate*)
1187c478bd9Sstevel@tonic-gate	(date; echo "${_errormsg}") | logger -p daemon.err
1197c478bd9Sstevel@tonic-gate	echo "${_errormsg}" | mailx root adm
1207c478bd9Sstevel@tonic-gate	echo "ERROR: runacct called with invalid arguments" > ${_active}
1217c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
1227c478bd9Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
1237c478bd9Sstevel@tonic-gate	exit 1
1247c478bd9Sstevel@tonic-gate	;;
1257c478bd9Sstevel@tonic-gateesac
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate#	"processing is broken down into seperate, restartable states"
1297c478bd9Sstevel@tonic-gate#	"the statefile is updated at the end of each state so that the"
1307c478bd9Sstevel@tonic-gate#	"next loop through the while statement switches to the next state"
1317c478bd9Sstevel@tonic-gatewhile [ 1 ]
1327c478bd9Sstevel@tonic-gatedo
1337c478bd9Sstevel@tonic-gatecase "`cat ${_statefile}`" in
1347c478bd9Sstevel@tonic-gateSETUP)
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gatecd ${_adm}
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate(date ; ls -l fee pacct* ${_wtmpx}* ) >> ${_active}
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate#	"switch current pacct file"
1417c478bd9Sstevel@tonic-gateturnacct switch
1427c478bd9Sstevel@tonic-gate_rc=$?
1437c478bd9Sstevel@tonic-gateif test ${_rc} -ne 0; then
1447c478bd9Sstevel@tonic-gate	(date ; echo "${_errormsg}" ) | logger -p daemon.err
1457c478bd9Sstevel@tonic-gate	echo "${_errormsg}" | mailx root adm
1467c478bd9Sstevel@tonic-gate	echo "ERROR: turnacct switch returned rc=${_rc}" >> ${_active}
1477c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
1487c478bd9Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
1497c478bd9Sstevel@tonic-gate	exit 1
1507c478bd9Sstevel@tonic-gatefi
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate#	" give pacct files unique names for easy restart "
1537c478bd9Sstevel@tonic-gatefor _i in pacct?*
1547c478bd9Sstevel@tonic-gatedo
1557c478bd9Sstevel@tonic-gate	if [ "${_i}" = "pacct?*" ]
1567c478bd9Sstevel@tonic-gate	then
1577c478bd9Sstevel@tonic-gate		rm -f ${_nite}/lock*
1587c478bd9Sstevel@tonic-gate		mv ${_active} ${_active}${_date}
1597c478bd9Sstevel@tonic-gate		exit 1
1607c478bd9Sstevel@tonic-gate	fi
1617c478bd9Sstevel@tonic-gate	if test -r S${_i}.${_date} ; then
1627c478bd9Sstevel@tonic-gate		 (date ; echo "${_errormsg}" ) | logger -p daemon.err
1637c478bd9Sstevel@tonic-gate		echo "${_errormsg}" | mailx root adm
1647c478bd9Sstevel@tonic-gate		echo "ERROR: S${_i}.${_date} already exists" >> ${_active}
1657c478bd9Sstevel@tonic-gate		echo "file setups probably already run" >> ${_active}
1667c478bd9Sstevel@tonic-gate		rm -f ${_nite}/lock*
1677c478bd9Sstevel@tonic-gate		mv ${_active} ${_active}${_date}
1687c478bd9Sstevel@tonic-gate		exit 1
1697c478bd9Sstevel@tonic-gate	fi
1707c478bd9Sstevel@tonic-gate	mv ${_i} S${_i}.${_date}
1717c478bd9Sstevel@tonic-gatedone
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate#	"add current time on end"
1757c478bd9Sstevel@tonic-gateif test -r ${_nite}/wtmpx.${_date} ; then
1767c478bd9Sstevel@tonic-gate	(date ; echo "${_errormsg}" ) | logger -p daemon.err
1777c478bd9Sstevel@tonic-gate	echo "${_errormsg}" | mailx root adm
1787c478bd9Sstevel@tonic-gate	echo "ERROR: ${_nite}/wtmpx.${_date} already exists: run setup manually" > ${_active}
1797c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
1807c478bd9Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
1817c478bd9Sstevel@tonic-gate	exit 1
1827c478bd9Sstevel@tonic-gatefi
1837c478bd9Sstevel@tonic-gateclosewtmp	# fudge a DEAD_PROCESS for /var/wtmpx
1847c478bd9Sstevel@tonic-gatecp ${_wtmpx} ${_nite}/${_date}.wtmpx
1857c478bd9Sstevel@tonic-gateacctwtmp "runacct" ${_nite}/${_date}.wtmpx
1867c478bd9Sstevel@tonic-gatenulladm ${_wtmpx}
1877c478bd9Sstevel@tonic-gateutmp2wtmp	# fudge active user from utmpx to wtmpx
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gateecho "files setups complete" >> ${_active}
1907c478bd9Sstevel@tonic-gateecho "WTMPFIX" > ${_statefile}
1917c478bd9Sstevel@tonic-gate;;
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gateWTMPFIX)
1947c478bd9Sstevel@tonic-gate#	"verify the integrity of the wtmpx file"
1957c478bd9Sstevel@tonic-gate#	"wtmpfix will automatically fix date changes"
1967c478bd9Sstevel@tonic-gatecd ${_nite}
1977c478bd9Sstevel@tonic-gatenulladm tmpwtmp wtmperror
1987c478bd9Sstevel@tonic-gatewtmpfix < ${_date}.wtmpx > tmpwtmp 2>wtmperror
1997c478bd9Sstevel@tonic-gateif test $? -ne 0 ; then
2007c478bd9Sstevel@tonic-gate	(date ; echo "${_errormsg}") | mailx root adm
2017c478bd9Sstevel@tonic-gate	echo "${_errormsg}" | logger -p daemon.err
2027c478bd9Sstevel@tonic-gate	echo "ERROR: wtmpfix errors see ${_nite}/wtmperror${_date}" >> ${_active}
2037c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
2047c478bd9Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
2057c478bd9Sstevel@tonic-gate	mv wtmperror wtmperror${_date}
2067c478bd9Sstevel@tonic-gate	exit 1
2077c478bd9Sstevel@tonic-gatefi
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gateecho "wtmpx processing complete" >> ${_active}
2107c478bd9Sstevel@tonic-gateecho "CONNECT" > ${_statefile}
2117c478bd9Sstevel@tonic-gate;;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gateCONNECT)
2157c478bd9Sstevel@tonic-gate#	"produce connect records"
2167c478bd9Sstevel@tonic-gate#	"the lineuse and reboots files are used by prdaily"
2177c478bd9Sstevel@tonic-gatecd ${_nite}
2187c478bd9Sstevel@tonic-gatenulladm lineuse reboots log ctacct.${_date}
2197c478bd9Sstevel@tonic-gateacctcon -l lineuse -o reboots < tmpwtmp  2> log > ctacct.${_date}
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate# if the following test is true, then pnpsplit complained about
2227c478bd9Sstevel@tonic-gate# the year and holidays not being up to date.  This used to be
2237c478bd9Sstevel@tonic-gate# a fatal error, but now it will continue to process the accounting.
2247c478bd9Sstevel@tonic-gate#
2257c478bd9Sstevel@tonic-gateif test -s log ; then
2267c478bd9Sstevel@tonic-gate	(date ; cat ${_nite}/log) | mailx adm root
227*5068e65bSsv	echo "\n\n************ ACCT ERRORS : see  ${_nite}log********\n\n" | logger -p daemon.err
2287c478bd9Sstevel@tonic-gate	cat ${_nite}/log >> ${_active}${_date}
2297c478bd9Sstevel@tonic-gatefi
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gateecho "connect acctg complete" >> ${_active}
2327c478bd9Sstevel@tonic-gateecho "PROCESS" > ${_statefile}
2337c478bd9Sstevel@tonic-gate;;
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gatePROCESS)
2377c478bd9Sstevel@tonic-gate#	"correlate Spacct and ptacct files by number"
2387c478bd9Sstevel@tonic-gate#	"will not process Spacct file if corresponding ptacct exists"
2397c478bd9Sstevel@tonic-gate#	"remove the ptacct file to rurun the Spacct file"
2407c478bd9Sstevel@tonic-gate#	"if death occurs here, rerunacct should remove last ptacct file"
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gatecd ${_nite}
2437c478bd9Sstevel@tonic-gatefor _Spacct in ${_adm}/Spacct*.${_date}
2447c478bd9Sstevel@tonic-gatedo
2457c478bd9Sstevel@tonic-gate	_ptacct=`basename ${_Spacct} | sed 's/Sp/pt/'`
2467c478bd9Sstevel@tonic-gate	if test -s ${_ptacct}; then
2477c478bd9Sstevel@tonic-gate		echo "WARNING: accounting already run for ${_Spacct}" \
2487c478bd9Sstevel@tonic-gate			>> ${_active}
2497c478bd9Sstevel@tonic-gate		echo "WARNING: remove ${_nite}/${_ptacct} to rerun" \
2507c478bd9Sstevel@tonic-gate			>> ${_active}
2517c478bd9Sstevel@tonic-gate	else
2527c478bd9Sstevel@tonic-gate		nulladm ${_ptacct}
2537c478bd9Sstevel@tonic-gate		acctprc < ${_Spacct} > ${_ptacct}
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate		echo "process acctg complete for ${_Spacct}" >> ${_active}
2567c478bd9Sstevel@tonic-gate	fi
2577c478bd9Sstevel@tonic-gatedone
2587c478bd9Sstevel@tonic-gateecho "all process actg complete for ${_date}" >> ${_active}
2597c478bd9Sstevel@tonic-gateecho "MERGE" > ${_statefile}
2607c478bd9Sstevel@tonic-gate;;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gateMERGE)
2647c478bd9Sstevel@tonic-gatecd ${_nite}
2657c478bd9Sstevel@tonic-gate#	"merge ctacct and ptacct files together"
2667c478bd9Sstevel@tonic-gateacctmerg ptacct*.${_date} < ctacct.${_date} > daytacct
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gateecho "tacct merge to create daytacct complete" >> ${_active}
2697c478bd9Sstevel@tonic-gateecho "FEES" > ${_statefile}
2707c478bd9Sstevel@tonic-gate;;
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gateFEES)
2747c478bd9Sstevel@tonic-gatecd ${_nite}
2757c478bd9Sstevel@tonic-gate#	"merge in fees"
2767c478bd9Sstevel@tonic-gateif test -s ${_adm}/fee; then
2777c478bd9Sstevel@tonic-gate	cp daytacct tmpdayt
2787c478bd9Sstevel@tonic-gate	sort +0n +2 ${_adm}/fee | acctmerg -i | acctmerg tmpdayt  > daytacct
2797c478bd9Sstevel@tonic-gate	echo "merged fees" >> ${_active}
2807c478bd9Sstevel@tonic-gate	rm -f tmpdayt
2817c478bd9Sstevel@tonic-gateelse
2827c478bd9Sstevel@tonic-gate	echo "no fees" >> ${_active}
2837c478bd9Sstevel@tonic-gatefi
2847c478bd9Sstevel@tonic-gateecho "DISK" > ${_statefile}
2857c478bd9Sstevel@tonic-gate;;
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gateDISK)
2897c478bd9Sstevel@tonic-gatecd ${_nite}
2907c478bd9Sstevel@tonic-gate#	"the last act of any disk acct procedure should be to mv its"
2917c478bd9Sstevel@tonic-gate#	"entire output file to disktacct, where it will be picked up"
2927c478bd9Sstevel@tonic-gateif test -r disktacct; then
2937c478bd9Sstevel@tonic-gate	cp daytacct tmpdayt
2947c478bd9Sstevel@tonic-gate	acctmerg disktacct  < tmpdayt > daytacct
2957c478bd9Sstevel@tonic-gate	echo "merged disk records" >> ${_active}
2967c478bd9Sstevel@tonic-gate	rm -f tmpdayt
2977c478bd9Sstevel@tonic-gate	mv disktacct /tmp/disktacct.${_date}
2987c478bd9Sstevel@tonic-gateelse
2997c478bd9Sstevel@tonic-gate	echo "no disk records" >> ${_active}
3007c478bd9Sstevel@tonic-gatefi
3017c478bd9Sstevel@tonic-gateecho "MERGETACCT" > ${_statefile}
3027c478bd9Sstevel@tonic-gate;;
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gateMERGETACCT)
3057c478bd9Sstevel@tonic-gatecd ${_adm}/acct
3067c478bd9Sstevel@tonic-gate#	"save each days tacct file in sum/tacct.${_date}"
3077c478bd9Sstevel@tonic-gate#	"if sum/tacct gets corrupted or lost, could recreate easily"
3087c478bd9Sstevel@tonic-gate#	"the monthly acctg procedure should remove all sum/tacct files"
3097c478bd9Sstevel@tonic-gatecp nite/daytacct sum/tacct${_date}
3107c478bd9Sstevel@tonic-gateif test ! -r sum/tacct; then
3117c478bd9Sstevel@tonic-gate	echo "WARNING: recreating ${_adm}/sum/tacct " >> ${_active}
3127c478bd9Sstevel@tonic-gate	nulladm sum/tacct
3137c478bd9Sstevel@tonic-gatefi
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate#	"merge in todays tacct with the summary tacct"
3167c478bd9Sstevel@tonic-gaterm -f sum/tacctprev
3177c478bd9Sstevel@tonic-gatecp sum/tacct sum/tacctprev
3187c478bd9Sstevel@tonic-gateacctmerg sum/tacctprev  < sum/tacct${_date} > sum/tacct
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gateecho "updated sum/tacct" >> ${_active}
3217c478bd9Sstevel@tonic-gateecho "CMS" > ${_statefile}
3227c478bd9Sstevel@tonic-gate;;
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gateCMS)
3267c478bd9Sstevel@tonic-gatecd ${_adm}/acct
3277c478bd9Sstevel@tonic-gate#	"do command summaries"
3287c478bd9Sstevel@tonic-gatenulladm sum/daycms
3297c478bd9Sstevel@tonic-gateif test ! -r sum/cms; then
3307c478bd9Sstevel@tonic-gate	nulladm sum/cms
3317c478bd9Sstevel@tonic-gate	echo "WARNING: recreating ${_adm}/sum/cms " >> ${_active}
3327c478bd9Sstevel@tonic-gatefi
3337c478bd9Sstevel@tonic-gatecp sum/cms sum/cmsprev
3347c478bd9Sstevel@tonic-gateacctcms ${_adm}/Spacct*.${_date}  > sum/daycms
3357c478bd9Sstevel@tonic-gateacctcms -s sum/daycms sum/cmsprev  > sum/cms
3367c478bd9Sstevel@tonic-gateacctcms -a -s sum/daycms | sed -n 1,56p  > nite/daycms
3377c478bd9Sstevel@tonic-gateacctcms -a -s sum/cms | sed -n 1,56p  > nite/cms
3387c478bd9Sstevel@tonic-gatelastlogin
3397c478bd9Sstevel@tonic-gateecho "command summaries complete" >> ${_active}
3407c478bd9Sstevel@tonic-gateecho "USEREXIT" > ${_statefile}
3417c478bd9Sstevel@tonic-gate;;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gateUSEREXIT)
3457c478bd9Sstevel@tonic-gate#	"any installation dependant accounting programs should be run here"
3467c478bd9Sstevel@tonic-gate[ -s /usr/lib/acct/runacct.local ] && /usr/lib/acct/runacct.local
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gateecho "CLEANUP" > ${_statefile}
3497c478bd9Sstevel@tonic-gate;;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gateCLEANUP)
3537c478bd9Sstevel@tonic-gatecd ${_adm}/acct
3547c478bd9Sstevel@tonic-gate#	" finally clear files; could be done next morning if desired"
3557c478bd9Sstevel@tonic-gatenulladm ${_adm}/fee
3567c478bd9Sstevel@tonic-gaterm -f ${_adm}/Spacct*.${_date}
3577c478bd9Sstevel@tonic-gate#	"put reports onto a file"
3587c478bd9Sstevel@tonic-gateprdaily >> sum/rprt${_date};
3597c478bd9Sstevel@tonic-gaterm -f nite/lock*
3607c478bd9Sstevel@tonic-gaterm -f nite/ptacct*.${_date} nite/ctacct.${_date}
3617c478bd9Sstevel@tonic-gatemv -f nite/${_date}.wtmpx nite/owtmpx
3627c478bd9Sstevel@tonic-gaterm -f nite/wtmperror${_date} nite/active${_date} nite/tmpwtmp
3637c478bd9Sstevel@tonic-gateecho "system accounting completed at `date`" >> ${_active}
3647c478bd9Sstevel@tonic-gateecho "********** SYSTEM ACCOUNTING COMPLETED `date` **********" | logger -p daemon.notice
3657c478bd9Sstevel@tonic-gateecho "COMPLETE" > ${_statefile}
3667c478bd9Sstevel@tonic-gateexit 0
3677c478bd9Sstevel@tonic-gate;;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate*)
3707c478bd9Sstevel@tonic-gate	(date;echo "${_errormsg}") | logger -p daemon.err
3717c478bd9Sstevel@tonic-gate	echo "${_errormsg}" | mailx adm root
3727c478bd9Sstevel@tonic-gate	echo "ERROR: invalid state, check ${_statefile}" >> active
3737c478bd9Sstevel@tonic-gate	rm -f ${_nite}/lock*
3747c478bd9Sstevel@tonic-gate	mv ${_active} ${_active}${_date}
3757c478bd9Sstevel@tonic-gate	exit 1
3767c478bd9Sstevel@tonic-gate	;;
3777c478bd9Sstevel@tonic-gateesac
3787c478bd9Sstevel@tonic-gatedone
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate#	" runacct is normally called with no arguments from the cron"
3827c478bd9Sstevel@tonic-gate#	" it checks its own locks to make sure that 2 crons or previous"
3837c478bd9Sstevel@tonic-gate#	" problems have not occured"
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate#	" runacct uses the statefile to record its progress"
3867c478bd9Sstevel@tonic-gate#	" each state updates the statefile upon completion"
3877c478bd9Sstevel@tonic-gate#	" then the next loop though the while picks up the new state"
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate#	" to restart this shell,  check the active file for diagnostics"
3907c478bd9Sstevel@tonic-gate#	" fix up any corrupted data (ie. bad pacct or wtmpx files)"
3917c478bd9Sstevel@tonic-gate#	" if runacct detected the error it removes the locks"
3927c478bd9Sstevel@tonic-gate#	" remove the locks if necessary, otherwise runacct will complain"
3937c478bd9Sstevel@tonic-gate#	" the lastdate file should be removed or changed"
3947c478bd9Sstevel@tonic-gate#	" restart runacct at current state with:  runacct MMDD"
3957c478bd9Sstevel@tonic-gate#	" to override the statefile: runacct MMDD STATE"
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate#	" if runacct has been executed after the latest failure"
3997c478bd9Sstevel@tonic-gate#	" ie. it ran ok today but failed yesterday"
4007c478bd9Sstevel@tonic-gate#	" the statefile will not be correct"
4017c478bd9Sstevel@tonic-gate#	" check the active files and restart properly"
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate#	" if runacct failed in the PROCESS state, remove the last"
4047c478bd9Sstevel@tonic-gate#	" ptacct file because it may not be complete"
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate#	" if shell has failed several days, do SETUP manually"
4077c478bd9Sstevel@tonic-gate#	" then rerun runacct once for each day failed"
4087c478bd9Sstevel@tonic-gate#	" could use fwtmp here to split up wtmpx file correctly"
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate#	" normally not a good idea to restart the SETUP state"
4117c478bd9Sstevel@tonic-gate#	" should be done manually, or just cleanup first"
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate#	" FILE USAGE:	all files in /var/adm/acct/nite unless specified"
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate#	" statefile	records progess of runacct"
4177c478bd9Sstevel@tonic-gate#	" lastdate	last day runacct ran in date +%m%d format"
4187c478bd9Sstevel@tonic-gate#	" lock lock1	controls serial use of runacct"
4197c478bd9Sstevel@tonic-gate#	" active	place for all descriptive and error messages"
4207c478bd9Sstevel@tonic-gate#	" fd2log	fd2 output for runacct ( see cron entry ) "
4217c478bd9Sstevel@tonic-gate#	" MMDD.wtmpx    owtmpx yesterdays wtmpx file"
4227c478bd9Sstevel@tonic-gate#	" tmpwtmp	yesterdays wtmp corrected by wtmpfix"
4237c478bd9Sstevel@tonic-gate#	" wtmperror	place for wtmpfix error messages"
4247c478bd9Sstevel@tonic-gate#	" lineuse	lineusage report used in prdaily"
4257c478bd9Sstevel@tonic-gate#	" reboots	reboots report used in prdaily"
4267c478bd9Sstevel@tonic-gate#	" log		place for error messages from acctcon1"
4277c478bd9Sstevel@tonic-gate#	" ctacct.MMDD	connect tacct records for MMDD"
4287c478bd9Sstevel@tonic-gate#	" ptacct.n.MMDD	process tacct records n files for MMDD"
4297c478bd9Sstevel@tonic-gate#	" daytacct	total tacct records for this days accounting"
4307c478bd9Sstevel@tonic-gate#	" disktacct	disk tacct records produced by disk shell"
4317c478bd9Sstevel@tonic-gate#	" daycms	ascii daily command summary used by prdaily"
4327c478bd9Sstevel@tonic-gate#	" cms		acsii total command summary used by prdaily"
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate#	" following files in /var/adm directory"
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate#	" fee		output from chargefee program"
4377c478bd9Sstevel@tonic-gate#	" pacct		active pacct file"
4387c478bd9Sstevel@tonic-gate#	" pacctn	switched pacct files"
4397c478bd9Sstevel@tonic-gate#	" Spacctn.MMDD	pacct files for MMDD after SETUP state"
4407c478bd9Sstevel@tonic-gate#	" wtmpx		active wtmpx file"
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate#	" following files in /var/adm/acct/sum"
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate#	" loginlog	output of lastlogin used in prdaily"
4457c478bd9Sstevel@tonic-gate#	" tacct		total tacct file for current fiscal"
4467c478bd9Sstevel@tonic-gate#	" tacct.MMDD	tacct file for day MMDD"
4477c478bd9Sstevel@tonic-gate#	" cms		total cms file for current fiscal"
4487c478bd9Sstevel@tonic-gate#	" rprt.MMDD	output of prdaily program"
4497c478bd9Sstevel@tonic-gate#	" MMDD.wtmpx	saved copy of wtmpx for MMDD"
4507c478bd9Sstevel@tonic-gate#	" pacct.MMDD	concatenated version of all pacct files for MMDD"
4517c478bd9Sstevel@tonic-gate#	" cmsprev	total cms file without latest update"
4527c478bd9Sstevel@tonic-gate#	" tacctprev	total tacct file without latest update"
4537c478bd9Sstevel@tonic-gate#	" daycms	cms files for todays usage"
454