System Administration Guide, Volume 2

The runacct Program

The main daily accounting shell script, runacct, is normally invoked by cron outside of prime business hours. The runacct shell script processes connect, fee, disk, and process accounting files. It also prepares daily and cumulative summary files for use by prdaily and monacct for billing purposes.

The runacct shell script takes care not to damage files if errors occur. A series of protection mechanisms are used that attempt to recognize an error, provide intelligent diagnostics, and complete processing in such a way that runacct can be restarted with minimal intervention. It records its progress by writing descriptive messages into the file active. (Files used by runacct are assumed to be in the /var/adm/acct/nite directory, unless otherwise noted.) All diagnostic output during the execution of runacct is written into fd2log.

When runacct is invoked, it creates the files lock and lock1. These files are used to prevent simultaneous execution of runacct. The runacct program prints an error message if these files exist when it is invoked. The lastdate file contains the month and day runacct was last invoked, and is used to prevent more than one execution per day. If runacct detects an error, a message is written to the console, mail is sent to root and adm, locks may be removed, diagnostic files are saved, and execution is ended. For instructions on how to start runacct again, see "How to Restart runacct".

To allow runacct to be restartable, processing is broken down into separate re-entrant states. The file statefile is used to keep track of the last state completed. When each state is completed, statefile is updated to reflect the next state. After processing for the state is complete, statefile is read and the next state is processed. When runacct reaches the CLEANUP state, it removes the locks and ends. States are executed as shown in the table below.

Table 32-7 runacct States

State 

Description 

SETUP

The command turnacct switch is executed to create a new pacct file. The process accounting files in /var/adm/pacctn (except for the pacct file) are moved to /var/adm/Spacctn.MMDD. The /var/adm/wtmpx file is moved to /var/adm/acct/nite/wtmp.MMDD (with the current time record added on the end) and a new /var/adm/wtmp is created. closewtmp and utmp2wtmp add records to wtmp.MMDD and the new wtmpx to account for users currently logged in.

WTMPFIX

The wtmpfix program checks the wtmp.MMDD file in the nite directory for accuracy. Because some date changes will cause acctcon to fail, wtmpfix attempts to adjust the time stamps in the wtmpx file if a record of a date change appears. It also deletes any corrupted entries from the wtmpx file. The fixed version of wtmp.MMDD is written to tmpwtmp.

CONNECT

The acctcon program is used to record connect accounting records in the file ctacct.MMDD. These records are in tacct.h format. In addition, acctcon creates the lineuse and reboots files. The reboots file records all the boot records found in the wtmpx file.

PROCESS

The acctprc program is used to convert the process accounting files, /var/adm/Spacctn.MMDD, into total accounting records in ptacctn.MMDD. The Spacct and ptacct files are correlated by number so that if runacct fails, the Spacct files will not be processed.

MERGE

The acctmerg program merges the process accounting records with the connect accounting records to form daytacct.

FEES

The acctmerg program merges ASCII tacct records from the fee file into daytacct.

DISK

If the dodisk procedure has been run, producing the disktacct file, the DISK program merges the file into daytacct and moves disktacct to /tmp/disktacct.MMDD.

MERGETACCT

The acctmerg program merges daytacct with sum/tacct, the cumulative total accounting file. Each day, daytacct is saved in sum/tacct.MMDD, so that sum/tacct can be recreated if it is corrupted or lost.

CMS

The acctcms program is run several times. acctcms is first run to generate the command summary using the Spacctn files and write it to sum/daycms. The acctcms program is then run to merge sum/daycms with the cumulative command summary file sum/cms. Finally, acctcms is run to produce the ASCII command summary files, nite/daycms and nite/cms, from the sum/daycms and sum/cms files, respectively. The lastlogin program is used to create the /var/adm/acct/sum/loginlog log file, the report of when each user last logged in. (If runacct is run after midnight, the dates showing the time last logged in by some users will be incorrect by one day.)

USEREXIT

Any installation-dependent (local) accounting program can be included at this point. runacct expects it to be called /usr/lib/acct/runacct.local.

CLEANUP

Cleans up temporary files, runs prdaily and saves its output in sum/rpt.MMDD, removes the locks, then exits.


Caution - Caution -

When restarting runacct in the CLEANUP state, remove the last ptacct file because it will not be complete.