#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
# All Rights Reserved
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
# "nitely accounting shell, should be run from cron (adm) at 4am"
# "does process, connect, disk, and fee accounting"
# "prepares command summaries"
# "shell is restartable and provides reasonable diagnostics"
export PATH
_errormsg="\n\n************ ACCT ERRORS : see ${_active}${_date}********\n\n"
_MIN_BLKS=500
cd ${_adm}
# "make sure that 2 crons weren't started, or leftover problems"
if test $? -ne 0; then
_lnkerr="\n\n*********** 2 CRONS or ACCT PROBLEMS***********\n\n\n"
echo "ERROR: locks found, run aborted" >> ${_active}
exit 1
fi
#
echo "Terminating procedure"
exit 1
fi
case $# in
0)
# "as called by the cron each day"
if test ! -r ${_lastdate} ; then
echo "0000" > ${_lastdate}
fi
exit 1
fi
echo "SETUP" > ${_statefile}
echo "\n\n\n\n\n********** SYSTEM ACCOUNTING STARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
;;
1)
# "runacct MMDD (date) will restart at current state"
_date=$1
_errormsg="\n\n************ ACCT ERRORS : see ${_active}${_date}********\n\n"
echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
;;
2)
# "runacct MMDD STATE restart at specified state"
_date=$1
_errormsg="\n\n************ ACCT ERRORS : see ${_active}${_date}********\n\n"
echo "restarting acctg for ${_date} at $2" >> ${_active}
echo "$2" > ${_statefile}
echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" | logger -p daemon.notice
;;
*)
echo "ERROR: runacct called with invalid arguments" > ${_active}
exit 1
;;
esac
# "processing is broken down into seperate, restartable states"
# "the statefile is updated at the end of each state so that the"
# "next loop through the while statement switches to the next state"
while [ 1 ]
do
cd ${_adm}
# "switch current pacct file"
turnacct switch
_rc=$?
echo "ERROR: turnacct switch returned rc=${_rc}" >> ${_active}
exit 1
fi
# " give pacct files unique names for easy restart "
do
if [ "${_i}" = "pacct?*" ]
then
exit 1
fi
echo "ERROR: S${_i}.${_date} already exists" >> ${_active}
echo "file setups probably already run" >> ${_active}
exit 1
fi
done
# "add current time on end"
echo "ERROR: ${_nite}/wtmpx.${_date} already exists: run setup manually" > ${_active}
exit 1
fi
utmp2wtmp # fudge active user from utmpx to wtmpx
echo "files setups complete" >> ${_active}
echo "WTMPFIX" > ${_statefile}
;;
# "verify the integrity of the wtmpx file"
# "wtmpfix will automatically fix date changes"
cd ${_nite}
if test $? -ne 0 ; then
echo "ERROR: wtmpfix errors see ${_nite}/wtmperror${_date}" >> ${_active}
exit 1
fi
echo "wtmpx processing complete" >> ${_active}
echo "CONNECT" > ${_statefile}
;;
# "produce connect records"
# "the lineuse and reboots files are used by prdaily"
cd ${_nite}
# if the following test is true, then pnpsplit complained about
# the year and holidays not being up to date. This used to be
# a fatal error, but now it will continue to process the accounting.
#
if test -s log ; then
fi
echo "connect acctg complete" >> ${_active}
echo "PROCESS" > ${_statefile}
;;
# "correlate Spacct and ptacct files by number"
# "will not process Spacct file if corresponding ptacct exists"
# "remove the ptacct file to rurun the Spacct file"
# "if death occurs here, rerunacct should remove last ptacct file"
cd ${_nite}
do
if test -s ${_ptacct}; then
echo "WARNING: accounting already run for ${_Spacct}" \
>> ${_active}
echo "WARNING: remove ${_nite}/${_ptacct} to rerun" \
>> ${_active}
else
echo "process acctg complete for ${_Spacct}" >> ${_active}
fi
done
echo "all process actg complete for ${_date}" >> ${_active}
echo "MERGE" > ${_statefile}
;;
cd ${_nite}
# "merge ctacct and ptacct files together"
echo "tacct merge to create daytacct complete" >> ${_active}
echo "FEES" > ${_statefile}
;;
FEES)
cd ${_nite}
# "merge in fees"
echo "merged fees" >> ${_active}
else
echo "no fees" >> ${_active}
fi
echo "DISK" > ${_statefile}
;;
DISK)
cd ${_nite}
# "the last act of any disk acct procedure should be to mv its"
# "entire output file to disktacct, where it will be picked up"
if test -r disktacct; then
echo "merged disk records" >> ${_active}
else
echo "no disk records" >> ${_active}
fi
echo "MERGETACCT" > ${_statefile}
;;
fi
# "merge in todays tacct with the summary tacct"
echo "CMS" > ${_statefile}
;;
CMS)
# "do command summaries"
fi
echo "command summaries complete" >> ${_active}
echo "USEREXIT" > ${_statefile}
;;
# "any installation dependant accounting programs should be run here"
echo "CLEANUP" > ${_statefile}
;;
# " finally clear files; could be done next morning if desired"
# "put reports onto a file"
echo "COMPLETE" > ${_statefile}
exit 0
;;
*)
echo "ERROR: invalid state, check ${_statefile}" >> active
exit 1
;;
esac
done
# " runacct is normally called with no arguments from the cron"
# " it checks its own locks to make sure that 2 crons or previous"
# " problems have not occured"
# " runacct uses the statefile to record its progress"
# " each state updates the statefile upon completion"
# " then the next loop though the while picks up the new state"
# " to restart this shell, check the active file for diagnostics"
# " fix up any corrupted data (ie. bad pacct or wtmpx files)"
# " if runacct detected the error it removes the locks"
# " remove the locks if necessary, otherwise runacct will complain"
# " the lastdate file should be removed or changed"
# " restart runacct at current state with: runacct MMDD"
# " to override the statefile: runacct MMDD STATE"
# " if runacct has been executed after the latest failure"
# " ie. it ran ok today but failed yesterday"
# " the statefile will not be correct"
# " check the active files and restart properly"
# " if runacct failed in the PROCESS state, remove the last"
# " ptacct file because it may not be complete"
# " if shell has failed several days, do SETUP manually"
# " then rerun runacct once for each day failed"
# " could use fwtmp here to split up wtmpx file correctly"
# " normally not a good idea to restart the SETUP state"
# " should be done manually, or just cleanup first"
# " statefile records progess of runacct"
# " lastdate last day runacct ran in date +%m%d format"
# " lock lock1 controls serial use of runacct"
# " active place for all descriptive and error messages"
# " fd2log fd2 output for runacct ( see cron entry ) "
# " MMDD.wtmpx owtmpx yesterdays wtmpx file"
# " tmpwtmp yesterdays wtmp corrected by wtmpfix"
# " wtmperror place for wtmpfix error messages"
# " lineuse lineusage report used in prdaily"
# " reboots reboots report used in prdaily"
# " log place for error messages from acctcon1"
# " ctacct.MMDD connect tacct records for MMDD"
# " ptacct.n.MMDD process tacct records n files for MMDD"
# " daytacct total tacct records for this days accounting"
# " disktacct disk tacct records produced by disk shell"
# " daycms ascii daily command summary used by prdaily"
# " cms acsii total command summary used by prdaily"
# " fee output from chargefee program"
# " pacct active pacct file"
# " pacctn switched pacct files"
# " Spacctn.MMDD pacct files for MMDD after SETUP state"
# " wtmpx active wtmpx file"
# " loginlog output of lastlogin used in prdaily"
# " tacct total tacct file for current fiscal"
# " tacct.MMDD tacct file for day MMDD"
# " cms total cms file for current fiscal"
# " rprt.MMDD output of prdaily program"
# " MMDD.wtmpx saved copy of wtmpx for MMDD"
# " pacct.MMDD concatenated version of all pacct files for MMDD"
# " cmsprev total cms file without latest update"
# " tacctprev total tacct file without latest update"
# " daycms cms files for todays usage"