System Administration Guide: Advanced Administration

How Daily Accounting Works

Here is a step-by-step summary of how daily accounting works:

  1. When the system is switched into multiuser mode, the /usr/lib/acct/startup program is executed. The startup program executes several other programs that invoke daily accounting.

  2. The acctwtmp program adds a “boot” record to the /var/adm/wtmpx file. In this record, the system name is shown as the user name in the wtmpx record. The following table summarizes how the raw accounting data is gathered and where it is stored.

    File in /var/adm

    Information Stored 

    Written By 

    Format 

    wtmpx

    Connect sessions  

    login, init

    Binary 

     

    Changes

    date

    Binary 

     

    Reboots

    acctwtmp

    Binary 

     

    Shutdowns

    shutacct

    Binary 

    pacctn

    Processes 

    Kernel (when the process ends)  

    Binary 

     

     

    turnacct switch (which creates a new file when the old file reaches 500 blocks)

    Binary 

    fee

    Special charges 

    chargefee

    ASCII 

    acct/nite/disktacct

    Disk space used 

    dodisk

    Binary 

  3. The turnacct script, invoked with the -on option, begins process accounting. Specifically, the turnacct script executes the accton program with the /var/adm/pacct argument.

  4. The remove shell script “cleans up” the saved pacct and wtmpx files that are left in the sum directory by the runacct script.

  5. The login and init programs record connect sessions by writing records into the /var/adm/wtmpx file. Date changes (using date with an argument) are also written to the /var/adm/wtmpx file. Reboots and shutdowns using the acctwtmp command are also recorded in the /var/adm/wtmpx file.

  6. When a process ends, the kernel writes one record per process, using the acct.h format, in the /var/adm/pacct file.

    Every hour, the cron command executes the ckpacct script to check the size of the /var/adm/pacct file. If the file grows beyond 500 blocks (default), the turnacct switch command is executed. (The program moves the pacct file to the pacctn file and creates a new file.) The advantage of having several smaller pacct files becomes apparent when you try to restart the runacct script if a failure occurs when processing these records.

  7. The runacct script is executed by the cron command each night. The runacct script processes the accounting files to produce command summaries and usage summaries by user name. These accounting files are processed: /var/adm/pacctn, /var/adm/wtmpx, /var/adm/fee, and /var/adm/acct/nite/disktacct.

  8. The /usr/lib/acct/prdaily script is executed on a daily basis by the runacct script to write the daily accounting information in the /var/adm/acct/sum/rprtMMDD files.

  9. The monacct script should be executed on a monthly basis (or at intervals you determine, such as at the end of every fiscal period). The monacct script creates a report that is based on data stored in the sum directory that has been updated daily by the runacct script. After creating the report, the monacct script “cleans up” the sum directory to prepare the directory's files for the new runacct data.