<chapter id="sysresacctsetup-78801"><title>Managing System
Accounting (Tasks)</title><highlights><para>This chapter describes how to set up and maintain system accounting.</para><itemizedlist><para>This is a list of the overview information in this chapter.</para><listitem><para><olink targetptr="sysresacctsetup-35" remap="internal">What is System Accounting?</olink></para>
</listitem><listitem><para><olink targetptr="sysresacctsetup-1" remap="internal">Setting Up System Accounting</olink></para>
</listitem>
</itemizedlist><para>For information on using extended accounting, see <olink targetdoc="sysadrm" targetptr="rmacct-1" remap="external">Chapter 4, <citetitle remap="chapter">Extended Accounting (Overview),</citetitle> in <citetitle remap="book">System Administration Guide:  Virtualization Using the Solaris Operating System</citetitle></olink>.</para><para>For information on the step-by-step procedures that are associated with
system accounting, see <olink targetptr="enmzl" remap="internal">System Accounting (Task Map)</olink>.</para><para>For reference information about the various system accounting reports,
see <olink targetptr="sysresacctref-14910" remap="internal">Chapter&nbsp;10, System Accounting
(Reference)</olink>.</para>
</highlights><sect1 id="esxhm"><title>What's New in System Accounting</title><para>This section describes new or changed features in system accounting
in the Solaris release.</para><sect2 id="etmju"><title>Solaris Process Accounting and Statistics Improvements</title><para><emphasis role="strong">Solaris 10:</emphasis> Changes have been made
to the internals of the load averaging, <filename>cpu usr/sys/idle</filename>,
and accounting functions. Microstate accounting has replaced the old accounting
mechanism and is enabled by default all of the time. As a result, you might
notice slightly different process usage and timing statistics.</para><para>Switching to microstate accounting provides substantially more accurate
data about user processes and the amount of time they spend in various states.
In addition, this information is used to generate more accurate load averages
and statistics from the <filename>/proc</filename> file system. For more information,
see the <olink targetdoc="refman" targetptr="proc-4" remap="external"><citerefentry><refentrytitle>proc</refentrytitle><manvolnum>4</manvolnum></citerefentry></olink> man
page.</para>
</sect2>
</sect1><sect1 id="sysresacctsetup-35"><title>What is System Accounting?</title><para>System accounting software in the Solaris OS is a set of programs that
enables you to collect and record data about user connect time, CPU time charged
to processes, and disk usage. Once you collect this data, you can generate
reports and charge fees for system usage.</para><para>You can use system accounting on a daily or monthly basis. Or, you can
tack disk usage per user.</para><itemizedlist><para>You can use the accounting programs to perform these
tasks:</para><listitem><para>Monitor system usage</para>
</listitem><listitem><para>Locate and correct performance problems</para>
</listitem><listitem><para>Maintain system security</para>
</listitem>
</itemizedlist><para>After you set up the system accounting programs, they run mostly on
their own.</para><sect2 id="sysresacctsetup-24"><title>How System Accounting Works</title><para>Automatic accounting is set up by first putting the accounting startup
script into root's <filename>crontab</filename> file. The accounting startup
script can then be started automatically by the <command>cron</command> command.</para><para>The following overview describes the system accounting process.</para><orderedlist><listitem><para>Between system startup and shutdown, raw data about system
use (such as user logins, running processes, and data storage) are collected
in accounting files.</para>
</listitem><listitem><para>Periodically (usually once a day), the <filename>/usr/lib/acct/runacct</filename> script processes the various accounting files and produces both
cumulative summary files and daily accounting reports. Then, the <filename>/usr/lib/acct/prdaily</filename> script prints the daily reports.</para><para>For more information
about the <command>runacct</command> script, see <olink targetptr="sysresacctref-41757" remap="internal">runacct Script</olink>.</para>
</listitem><listitem><para>Monthly, you can process and print the cumulative <filename>runacct</filename> summary files by executing the <filename>monacct</filename> script.
The summary reports produced by the <filename>monacct</filename> script provide
an efficient means for billing users on a monthly or other fiscal basis.</para>
</listitem>
</orderedlist>
</sect2><sect2 id="sysresacctsetup-2"><title>System Accounting Components</title><para>The system accounting software provides C language programs and shell
scripts that organize data into summary files and reports. These programs
reside in the <filename>/usr/lib/acct</filename> directory. The accounting
reports reside in the <filename>/var/adm/acct</filename> directory.</para><itemizedlist><para>Daily accounting can help you perform four types of auditing:</para><listitem><para>Connect accounting</para>
</listitem><listitem><para>Process accounting</para>
</listitem><listitem><para>Disk accounting</para>
</listitem><listitem><para>Fee calculations</para>
</listitem>
</itemizedlist><sect3 id="sysresacctsetup-42"><title>Connect Accounting</title><itemizedlist><para>Connect accounting enables you to determine the following
information:</para><listitem><para>The length of time a user was logged in</para>
</listitem><listitem><para>How the <literal>tty</literal> lines are being used</para>
</listitem><listitem><para>The number of reboots on your system</para>
</listitem><listitem><para>How many times the accounting software was turned off and
on</para>
</listitem>
</itemizedlist><itemizedlist><para>To provide this information on connect sessions, the system stores the
following data</para><listitem><para>Record of time adjustments</para>
</listitem><listitem><para>Boot times</para>
</listitem><listitem><para>Number of times the accounting software was turned off and
on</para>
</listitem><listitem><para>Changes in run levels</para>
</listitem><listitem><para>The creation of user processes (<literal>login</literal> processes
and <literal>init</literal> processes)</para>
</listitem><listitem><para>The terminations of processes</para>
</listitem>
</itemizedlist><para>These records are produced from the
output of system programs such as <command>date</command>, <command>init</command>, <command>login</command>, <command>ttymon</command>, and <command>acctwtmp</command>.
They are stored in the <filename>/var/adm/wtmpx</filename> file. </para><itemizedlist><para>Entries in the <filename>wtmpx</filename> file can contain the following
information: </para><listitem><para>Login name</para>
</listitem><listitem><para>Device name</para>
</listitem><listitem><para>Process ID</para>
</listitem><listitem><para>Entry type</para>
</listitem><listitem><para>Time stamp that denotes when the entry was made</para>
</listitem>
</itemizedlist>
</sect3><sect3 id="sysresacctsetup-18"><title>Process Accounting</title><itemizedlist><para>Process accounting enables you to keep track of the following
data about each process that runs on your system:</para><listitem><para>User IDs and group IDs of users using the process</para>
</listitem><listitem><para>Beginning times and elapsed times of the process</para>
</listitem><listitem><para>CPU time for the process (user time and system time)</para>
</listitem><listitem><para>Amount of memory used by the process</para>
</listitem><listitem><para>Commands run by the process</para>
</listitem><listitem><para>The <literal>tty</literal> that controls the process </para>
</listitem>
</itemizedlist><para>Every time a process terminates, the <command>exit</command> program
collects this information and writes it to the <filename>/var/adm/pacct</filename> file. </para>
</sect3><sect3 id="sysresacctsetup-15"><title>Disk Accounting</title><itemizedlist><para>Disk accounting enables you to gather and format the following
data about the files each user has on disks:</para><listitem><para>User name and user ID of the user</para>
</listitem><listitem><para>Number of blocks that are used by the user's files</para>
</listitem>
</itemizedlist><para>This data
is collected by the <filename>/usr/lib/acct/dodisk</filename> shell script
at intervals that are determined by the entry you add to the <filename>/var/spool/cron/crontabs/root</filename> file. In turn, the <command>dodisk</command> script invokes the <command>acctdisk</command> and <command>acctdusg</command> commands. These commands
gather disk usage by login name.</para><caution><para>Information
gathered by running the <command>dodisk</command> script is stored in the <filename>/var/adm/acct/nite/disktacct</filename> file. This information is overwritten
the next time the <command>dodisk</command> script is run. Therefore, avoid
running the <command>dodisk</command> script twice in the same day.</para>
</caution><para>The <command>acctdusg</command> command
might overcharge for files that are written randomly, which can create holes
in the files. This problem occurs because the <command>acctdusg</command> command
does not read the indirect blocks of a file when determining the file size.
Rather, the <command>acctdusg</command> command determines the file size by
checking the current file size value in the file's inode.</para>
</sect3><sect3 id="sysresacctsetup-10"><title>Fee Calculations</title><para>The <command>chargefee</command> utility
stores charges for special services that are provided to a user in the <filename>/var/adm/fee</filename> file. A special service, for example, is file restoration.
Each entry in the file consists of a user login name, user ID, and the fee.
This file is checked by the <command>runacct</command> script every day, and
new entries are merged into the accounting records. For instructions on running
the <command>chargefee</command> script to bill users, see <olink targetptr="sysresacctsetup-12261" remap="internal">How to Bill Users</olink>.</para>
</sect3><sect3 id="sysresacctsetup-58"><title>How Daily Accounting Works</title><para>Here is a step-by-step summary
of how daily accounting works: </para><orderedlist><listitem><para>When the system is switched
into multiuser mode, the <command>/usr/lib/acct/startup</command> program
is executed. The <command>startup</command> program executes several other
programs that invoke daily accounting.  </para>
</listitem><listitem><para>The <command>acctwtmp</command> program adds a &ldquo;boot&rdquo; record to the <filename>/var/adm/wtmpx</filename> file. In this record, the system name is shown as the user name
in the <filename>wtmpx</filename> record. The following table summarizes how
the raw accounting data is gathered and where it is stored.  </para><informaltable frame="topbot"><tgroup cols="4" colsep="0" rowsep="0"><colspec colname="column1" colwidth="108*"/><colspec colname="column2" colwidth="90*"/><colspec colname="column3" colwidth="87*"/><colspec colname="column4" colwidth="72*"/><thead><row rowsep="1"><entry><para>File in <filename>/var/adm</filename></para>
</entry><entry><para>Information Stored</para>
</entry><entry><para>Written By</para>
</entry><entry><para>Format</para>
</entry>
</row>
</thead><tbody><row><entry><para><filename>wtmpx</filename>  </para>
</entry><entry><para>Connect sessions </para>
</entry><entry><para><command>login</command>, <command>init</command></para>
</entry><entry><para>Binary</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para>Changes </para>
</entry><entry><para><command>date</command></para>
</entry><entry><para>Binary</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para>Reboots  </para>
</entry><entry><para><filename>acctwtmp</filename></para>
</entry><entry><para>Binary</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para>Shutdowns
 </para>
</entry><entry><para><command>shutacct</command></para>
</entry><entry><para>Binary</para>
</entry>
</row><row><entry><para><filename>pacctn</filename>    </para>
</entry><entry><para>Processes</para>
</entry><entry><para>Kernel (when the process ends) </para>
</entry><entry><para>Binary</para>
</entry>
</row><row><entry><para></para>
</entry><entry><para></para>
</entry><entry><para><command>turnacct switch</command> (which creates a
new file when the old file reaches 500 blocks) </para>
</entry><entry><para>Binary</para>
</entry>
</row><row><entry><para><filename>fee</filename>      </para>
</entry><entry><para>Special charges</para>
</entry><entry><para><command>chargefee</command></para>
</entry><entry><para>ASCII</para>
</entry>
</row><row><entry><para><filename>acct/nite/disktacct</filename></para>
</entry><entry><para>Disk space used</para>
</entry><entry><para><command>dodisk</command></para>
</entry><entry><para>Binary</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</listitem><listitem><para>The <command>turnacct</command> script, invoked with the <option>on</option> option, begins process accounting. Specifically, the <command>turnacct</command> script executes the <command>accton</command> program with the <filename>/var/adm/pacct</filename> argument.</para>
</listitem><listitem><para>The remove shell script &ldquo;cleans up&rdquo; the saved <filename>pacct</filename> and <filename>wtmpx</filename> files that are left in the <filename>sum</filename> directory by the <command>runacct</command> script.</para>
</listitem><listitem><para>The <command>login</command> and <command>init</command> programs record connect sessions by writing records into the <filename>/var/adm/wtmpx</filename> file. Date changes (using date with an argument)
are also written to the <filename>/var/adm/wtmpx</filename> file. Reboots
and shutdowns using the <command>acctwtmp</command> command are also recorded
in the <filename>/var/adm/wtmpx</filename> file.</para>
</listitem><listitem><para>When a process ends, the kernel writes one record per process,
using the <filename>acct.h</filename> format, in the <filename>/var/adm/pacct</filename> file.</para><para>Every hour, the <command>cron</command> command
executes the <command>ckpacct</command> script to check the size of the <filename>/var/adm/pacct</filename> file. If the file grows beyond 500 blocks (default),
the <command>turnacct switch</command> command is executed. (The program moves
the <filename>pacct</filename> file to the <command>pacct</command><replaceable>n</replaceable> file and creates a new file.) The advantage of having several
smaller <filename>pacct</filename> files becomes apparent when you try to
restart the <command>runacct</command> script if a failure occurs when processing
these records.</para>
</listitem><listitem><para>The <command>runacct</command> script is executed by the <command>cron</command> command
each night. The <command>runacct</command> script processes the accounting
files to produce command summaries and usage summaries by user name. These
accounting files are processed: <filename>/var/adm/pacct</filename><replaceable>n</replaceable>, <filename>/var/adm/wtmpx</filename>, <filename>/var/adm/fee</filename>,
and <filename>/var/adm/acct/nite/disktacct</filename>.</para>
</listitem><listitem><para>The <command>/usr/lib/acct/prdaily</command> script is executed on a daily basis by the <command>runacct</command> script to write the daily accounting information in the <command>/var/adm/acct/sum/rprt</command><replaceable>MMDD</replaceable> files.   </para>
</listitem><listitem><para>The <command>monacct</command> script should be executed on a
monthly basis (or at intervals you determine, such as at the end of every
fiscal period). The <command>monacct</command> script creates a report that
is based on data stored in the <filename>sum</filename> directory that has
been updated daily by the <command>runacct</command> script. After creating
the report, the <command>monacct</command> script &ldquo;cleans up&rdquo;
the <filename>sum</filename> directory to prepare the directory's files for
the new <command>runacct</command> data. </para>
</listitem>
</orderedlist>
</sect3><sect3 id="sysresacctref-1"><title>What Happens if the System Shuts Down</title><para>If the system is shut down by using the <command>shutdown</command> command, the <command>shutacct</command> script is executed
automatically. The <command>shutacct</command> script writes a <emphasis>reason
record</emphasis> into the <filename>/var/adm/wtmpx</filename> file and turns
off process accounting.</para>
</sect3>
</sect2>
</sect1><sect1 id="enmzl"><title>System Accounting (Task Map)</title><informaltable frame="all"><tgroup cols="3" colsep="1" rowsep="1"><colspec colwidth="22.46*"/><colspec colwidth="52.96*"/><colspec colwidth="23.57*"/><thead><row><entry><para>Task</para>
</entry><entry><para>Description</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Set up system accounting.</para>
</entry><entry><itemizedlist><para>Set up system accounting by performing the following tasks:</para><listitem><para>Create the <filename>/etc/rc0.d/K22acct</filename> and <filename>/etc/rc2.d/S22acct</filename> files.</para>
</listitem><listitem><para>Modify the <filename>/var/spool/cron/crontabs/adm</filename> and <filename>/var/spool/cron/crontabs/root</filename> <filename>crontab</filename> files.</para>
</listitem>
</itemizedlist>
</entry><entry><para><olink targetptr="sysresacctsetup-41702" remap="internal">How to Set Up System Accounting</olink></para>
</entry>
</row><row><entry><para>Bill users.</para>
</entry><entry><para>Run the <filename>/usr/lib/acct/chargefee</filename> <replaceable>username</replaceable> <replaceable>amount</replaceable> command.</para>
</entry><entry><para><olink targetptr="sysresacctsetup-12261" remap="internal">How to Bill Users</olink></para>
</entry>
</row><row><entry><para>Fix a corrupted <filename>wtmpx</filename> file.</para>
</entry><entry><para>Convert the <filename>wtmpx</filename> file from binary to ASCII format.</para>
</entry><entry><para><olink targetptr="sysresacctsetup-90762" remap="internal">How to Fix a Corrupted wtmpx
File</olink></para>
</entry>
</row><row><entry><para>Fix <filename>tacct</filename> errors.</para><para><command></command></para>
</entry><entry><para>Run the <command>prtacct</command> script to check the <filename>/var/adm/acct/sum/tacctprev</filename> file. Then, patch the latest<command>/var/adm/acct/sum/tacct</command><replaceable>MMDD</replaceable> file. You will need to re-create the <filename>/var/adm/acct/sum/tacct</filename> file.</para>
</entry><entry><para><olink targetptr="sysresacctsetup-22" remap="internal">How to Fix tacct Errors</olink></para>
</entry>
</row><row><entry><para>Restart the <command>runacct</command> script.</para>
</entry><entry><para>Remove the <filename>lastdate</filename> file and any lock files. Then,
manually restart the <command>runacct</command> script.</para>
</entry><entry><para><olink targetptr="sysresacctsetup-92960" remap="internal">How to Restart the runacct
Script</olink></para>
</entry>
</row><row><entry><para>Disable system accounting temporarily.</para>
</entry><entry><para>Edit the<literal>adm</literal> <filename>crontab</filename> file to
stop the <filename>ckpacct</filename>, <filename>runacct</filename>, and <filename>monacct</filename> programs from running.</para>
</entry><entry><para><olink targetptr="sysresacctsetup-41705" remap="internal">How to Temporarily Stop System
Accounting</olink></para>
</entry>
</row><row><entry><para>Disable system accounting permanently.</para>
</entry><entry><para>Delete the entries for the <command>ckpacct</command>, <command>runacct</command>,
and <command>monacct</command> programs in the <filename>adm</filename> and <filename>crontab</filename> files.</para>
</entry><entry><para><olink targetptr="sysresacctsetup-41703" remap="internal">How to Permanently Disable
System Accounting</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1><sect1 id="sysresacctsetup-1"><title>Setting Up System Accounting</title><para>You can set up system accounting to run while the system is in multiuser
mode (Run Level 2). Generally, this task involves these steps:</para><orderedlist><listitem><para>Creating the <filename>/etc/rc0.d/K22acct</filename> and <filename>/etc/rc2.d/S22acct</filename> startup scripts</para>
</listitem><listitem><para>Modifying the <filename>/var/spool/cron/crontabs/adm</filename> and <filename>/var/spool/cron/crontabs/root</filename> <filename>crontab</filename> files</para>
</listitem>
</orderedlist><para>The following table describes the default accounting scripts.
   </para><table frame="topbot" id="sysresacctsetup-tbl-2"><title>Default Accounting
Scripts</title><tgroup cols="4" colsep="0" rowsep="0"><colspec colname="colspec1" colwidth="109.00*"/><colspec colname="column1" colwidth="109*"/><colspec colname="colspec0" colwidth="109.00*"/><colspec colname="column3" colwidth="90*"/><thead><row rowsep="1"><entry><para>Purpose</para>
</entry><entry><para>Accounting Script</para>
</entry><entry><para>Man Page</para>
</entry><entry><para>Run Frequency</para>
</entry>
</row>
</thead><tbody><row><entry><para>Checks the size of the <filename>/usr/adm/pacct</filename> log file
and makes sure that it does not get too large.</para>
</entry><entry><para><filename>ckpacct</filename></para>
</entry><entry><para><olink targetdoc="refman" targetptr="acctsh-1m" remap="external"><citerefentry><refentrytitle>acctsh</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink></para>
</entry><entry><para>Periodically</para>
</entry>
</row><row><entry><para>Processes connect, disk, and fee accounting information. You can remove
from this script the commands for the accounting features you do not want
processed.</para>
</entry><entry><para><command>runacct</command></para>
</entry><entry><para><olink targetdoc="refman" targetptr="runacct-1m" remap="external"><citerefentry><refentrytitle>runacct</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink></para>
</entry><entry><para>Daily</para>
</entry>
</row><row><entry><para>Generates fiscal accounting summary reports on a monthly basis. You
can determine how often this script is run. You can remove from this script
the commands for the accounting features you do not want to use.</para>
</entry><entry><para><filename>monacct</filename></para>
</entry><entry><para><olink targetdoc="refman" targetptr="acctsh-1m" remap="external"><citerefentry><refentrytitle>acctsh</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink></para>
</entry><entry><para>On a fiscal basis</para>
</entry>
</row>
</tbody>
</tgroup>
</table><para>You can choose which accounting scripts run by default. After these
entries have been added to the <filename>crontab</filename> files, system
accounting should run automatically. </para><task id="sysresacctsetup-41702"><title>How to Set Up System Accounting</title><procedure>&rolestep.sgm;<step id="sysresacctsetup-step-5"><para>If necessary, install the <literal>SUNWaccr</literal> and <literal>SUNWaccu</literal> packages on your system by using the <command>pkgadd</command> command.</para>
</step><step id="sysresacctsetup-step-6"><para>Install <filename>/etc/init.d/acct</filename> as the
startup script for Run Level 2.  </para><screen># <userinput>ln /etc/init.d/acct /etc/rc2.d/S22acct</userinput></screen>
</step><step id="sysresacctsetup-step-7"><para>Install <filename>/etc/init.d/acct</filename> as
the stop script for Run Level 0.</para><screen># <userinput>ln /etc/init.d/acct /etc/rc0.d/K22acct</userinput></screen>
</step><step id="sysresacctsetup-step-8"><para>Add the following lines to the <literal>adm</literal> <filename>crontab</filename> file to start the <command>ckpacct</command>, <command>runacct</command>, and <command>monacct</command> scripts automatically.</para><screen># <userinput>EDITOR=vi; export EDITOR</userinput>
# <userinput>crontab -e adm</userinput>
0 * * * * /usr/lib/acct/ckpacct
30 2 * * * /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log
30 7 1 * * /usr/lib/acct/monacct</screen>
</step><step id="sysresacctsetup-step-9"><para>Add the following line to the <literal>root</literal> <filename>crontab</filename> file to start the <command>dodisk</command> script
automatically.</para><screen># <userinput>crontab -e</userinput>
30 22 * * 4 /usr/lib/acct/dodisk</screen>
</step><step id="sysresacctsetup-step-10"><para>Edit <filename>/etc/acct/holidays</filename> to include
national holidays and local holidays.</para><para>For more information, see
the <olink targetdoc="refman" targetptr="holidays-4" remap="external"><citerefentry><refentrytitle>holidays</refentrytitle><manvolnum>4</manvolnum></citerefentry></olink> man
page and the example that follows.</para>
</step><step id="sysresacctsetup-step-29"><para>Reboot the system, or start system
accounting manually by typing:</para><screen># <userinput>/etc/init.d/acct start</userinput></screen>
</step>
</procedure><example id="emjgh"><title>Setting Up Accounting (<command>adm crontab</command>)</title><para>This modified <command>adm crontab</command> contains
entries for the <filename>ckpacct</filename>, <filename>runacct</filename>,
and <filename>monacct</filename> scripts. </para><screen>#ident  "@(#)adm        1.5     92/07/14 SMI"    /* SVr4.0 1.2   */
#
# The adm crontab file should contain startup of performance 
# collection if the profiling and performance feature has been 
# installed.
0 * * * * /usr/lib/acct/ckpacct
30 2 * * * /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log
30 7 1 * * /usr/lib/acct/monacct</screen>
</example><example id="enmzp"><title>Setting Up Accounting (<command>root crontab</command>)</title><para>This
modified <command>root crontab</command> contains entries for the <filename>dodisk</filename> program.</para><screen>#ident  "@(#)root       1.19    98/07/06 SMI"   /* SVr4.0 1.1.3.1       */
#
# The root crontab should be used to perform accounting data collection.
#
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] &amp;&amp; /usr/lib/gss/gsscred_clean
30 22 * * 4 /usr/lib/acct/dodisk</screen>
</example><example id="enmzr"><title>Setting Up Accounting (<filename>/etc/acct/holidays</filename>)</title><para>The following example shows a sample <filename>/etc/acct/holidays</filename> file.
 </para><screen>* @(#)holidays	January 1, 2004
*
* Prime/Nonprime Table for UNIX Accounting System
*
* Curr	Prime	Non-Prime
* Year	Start	Start
*
  2004	0800	1800
*
* only the first column (month/day) is significant.
*
* month/day	Company
* 		Holiday
*
1/1		New Years Day
7/4		Indep. Day
12/25		Christmas</screen>
</example>
</task>
</sect1><sect1 id="sysresacctsetup-30"><title>Billing Users</title><para>If you provide special
user services by request. Special services include restoring files or remote
printing. You might want to bill users by running the <command>chargefee</command> utility.
The <command>chargefee</command> utility records charges in the <filename>/var/adm/fee</filename> file. Each time the <command>runacct</command> utility is executed,
new entries are merged into the total accounting records.         </para><para>See the <olink targetdoc="refman" targetptr="acctsh-1m" remap="external"><citerefentry><refentrytitle>acctsh</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> man
page for more information. </para><task id="sysresacctsetup-12261"><title>How to Bill Users</title><procedure>&rolestep.sgm;<step id="sysresacctsetup-step-14"><para>Charge a user for special services.
 </para><screen># <userinput>/usr/lib/acct/chargefee</userinput> <replaceable>username</replaceable> <replaceable>amount</replaceable></screen><variablelist><varlistentry><term><replaceable>username</replaceable></term><listitem><para>Is the user account you want to bill.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>amount</replaceable></term><listitem><para>Specifies the number of units to bill the user. This value
is an arbitrary unit that you set to charge users based on some task such
as printing or restoring a file. You would have to write a script that invokes
the <command>chargefee</command> utility and charges a user for a specific
task.</para>
</listitem>
</varlistentry>
</variablelist>
</step>
</procedure><example id="emjgg"><title>Billing Users</title><para>In the following example, the user <literal>print_customer</literal> is
charged 10 units.</para><screen># <userinput>/usr/lib/acct/chargefee print_customer 10</userinput></screen>
</example>
</task>
</sect1><sect1 id="sysresacctsetup-16"><title>Maintaining Accounting Information</title><para>This section describes how to fix corrupted system accounting files
and how to restart the <command>runacct</command> script.</para><sect2 id="sysresacctsetup-17"><title>Fixing Corrupted Files and <filename>wtmpx</filename> Errors</title><para>Unfortunately, system accounting is not foolproof. Occasionally,
a file becomes corrupted or lost. Some files can simply be ignored or restored
from backup. However, certain files must be fixed to maintain the integrity
of system accounting. </para><para>The <filename>wtmpx</filename> files seem to cause the
most problems in the daily operation of system accounting. When the date is
changed manually and the system is in multiuser mode, a set of date change
records is written to the <filename>/var/adm/wtmpx</filename> file. The <command>wtmpfix</command> utility is designed to adjust the time stamps in the <filename>wtmp</filename> records when a date change is encountered. However, some combinations
of date changes and reboots slip through the <command>wtmpfix</command> utility
and cause the <command>acctcon</command> program to fail.</para>
</sect2><task id="sysresacctsetup-90762"><title>How to Fix a Corrupted <filename>wtmpx</filename> File</title><procedure>&rolestep.sgm;<step id="sysresacctsetup-step-18"><para>Change to the <filename>/var/adm</filename> directory.</para>
</step><step id="sysresacctsetup-step-19"><para>Convert the <filename>wtmpx</filename> file
from binary format to ASCII format.</para><screen># <userinput>/usr/lib/acct/fwtmp &lt; wtmpx > wtmpx.ascii</userinput> </screen>
</step><step id="sysresacctsetup-step-20"><para>Edit the <filename>wtmpx.ascii</filename> file
to delete the corrupted records.</para>
</step><step id="sysresacctsetup-step-21"><para>Convert the <filename>wtmpx.ascii</filename> file back to a binary file.    </para><screen># <userinput>/usr/lib/acct/fwtmp -ic &lt; wtmpx.ascii > wtmpx</userinput></screen><para>See the <olink targetdoc="refman" targetptr="fwtmp-1m" remap="external"><citerefentry><refentrytitle>fwtmp</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> man
page for more information.</para>
</step>
</procedure>
</task><sect2 id="sysresacctsetup-31"><title>Fixing <filename>tacct</filename> Errors</title><para>The integrity of the <filename>/var/adm/acct/sum/tacct</filename> file
is important if you are charging users for system resources. Occasionally,
unusual <filename>tacct</filename> records appear with negative numbers, duplicate
user IDs, or a user ID of 65535. First, check the <filename>/var/adm/acct/sum/tacctprev</filename> file by using the <command>prtacct</command> script to print the
file. If the contents look all right, patch the latest <command>/var/adm/acct/sum/tacct</command><replaceable>MMDD</replaceable> file. Then, re-create the <filename>/var/adm/acct/sum/tacct</filename> file. The following steps outline a simple patch procedure.</para>
</sect2><task id="sysresacctsetup-22"><title>How to Fix <filename>tacct</filename> Errors</title><procedure>&rolestep.sgm;<step id="sysresacctsetup-step-23"><para>Change to the <filename>/var/adm/acct/sum</filename> directory.</para>
</step><step id="sysresacctsetup-step-24"><para>Convert the <filename>tacct</filename><replaceable>MMDD</replaceable> file from binary format to ASCII format.</para><screen># <userinput>/usr/lib/acct/acctmerg -v &lt; tacct</userinput><replaceable>MMDD</replaceable> <userinput>> xtacct</userinput></screen><para><replaceable>MMDD</replaceable> is pair of two-digit numbers that represent
the month and day.</para>
</step><step id="sysresacctsetup-step-25"><para>Edit the <filename>xtacct</filename> file,
removing corrupted records and writing duplicate records to another file. </para>
</step><step id="sysresacctsetup-step-26"><para>Convert the <filename>xtacct</filename> file
from ASCII format to binary format. </para><screen># <userinput>/usr/lib/acct/acctmerg -i &lt; xtacct > tacct</userinput><replaceable>MMDD</replaceable></screen>
</step><step id="sysresacctsetup-step-27"><para>Merge the files <filename>tacctprev</filename> and <filename>tacct.</filename><replaceable>MMDD</replaceable> into the <filename>tacct</filename> file. </para><screen># <userinput>/usr/lib/acct/acctmerg &lt; tacctprev tacct</userinput><replaceable>MMDD</replaceable> <userinput>> tacct</userinput></screen>
</step>
</procedure>
</task><sect2 id="sysresacctsetup-28"><title>Restarting the <command>runacct</command> Script</title><para>The <filename>runacct</filename> script can fail for
several reasons. </para><itemizedlist><para>The following are the most common reasons: </para><listitem><para>A system crash</para>
</listitem><listitem><para>The <filename>/var</filename> directory is running out of
space</para>
</listitem><listitem><para>A corrupted <filename>wtmpx</filename> file</para>
</listitem>
</itemizedlist><para>If the <filename>active</filename>.<replaceable>MMDD</replaceable> file
exists, check it first for error messages. If the <filename>active</filename> and <filename>lock</filename> files exist, check the <filename>fd2log</filename> file for
any relevant messages.</para><para>Run without
arguments, the <command>runacct</command> script assumes that this invocation
is the first invocation of the day. The argument <replaceable>MMDD</replaceable> is
necessary if the <command>runacct</command> script is being restarted and
specifies the month and day for which the <command>runacct</command> script
reruns the accounting. The entry point for processing is based on the contents
of the <filename>statefile</filename> file. To override the <filename>statefile</filename> file,
include the desired state on the command line. For a description of the available
states, see the <olink targetdoc="refman" targetptr="runacct-1m" remap="external"><citerefentry><refentrytitle>runacct</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> man
page.   </para><caution><para>When you run the <command>runacct</command> program manually,
be sure to run it as user <literal>adm</literal>.</para>
</caution>
</sect2><task id="sysresacctsetup-92960"><title>How to Restart the <filename>runacct</filename> Script</title><procedure><step><para>Change directories to the <filename>/var/adm/acct/nite</filename> directory.</para><screen>$ <userinput>cd /var/adm/acct/nite</userinput></screen>
</step><step id="sysresacctsetup-step-33"><para>Remove the <filename>lastdate</filename> file
and any <filename>lock</filename>* files, if any.</para><screen>$ <userinput>rm lastdate lock*</userinput></screen><para>The <filename>lastdate</filename> file contains the date that the <command>runacct</command> program was last run. Restarting the <command>runacct</command> script
in the next step re-creates this file.</para>
</step><step id="sysresacctsetup-step-34"><para>Restart the <command>runacct</command> script.</para><screen>$ <userinput>/usr/lib/acct/runacct</userinput> <replaceable>MMDD</replaceable> [<replaceable>state</replaceable>] <userinput>2> /var/adm/acct/nite/fd2log &amp;</userinput></screen><variablelist><varlistentry><term><replaceable>MMDD</replaceable></term><listitem><para>Is the month and day specified by two-digit numbers.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>state</replaceable></term><listitem><para>Specifies a state, or starting point, where the <filename>runacct</filename> script
processing should begin.  </para>
</listitem>
</varlistentry>
</variablelist>
</step>
</procedure>
</task>
</sect1><sect1 id="sysresacctsetup-41704"><title>Stopping and Disabling System Accounting</title><para>You can temporarily stop system accounting or permanently disable it.</para><task id="sysresacctsetup-41705"><title>How to Temporarily Stop System Accounting</title><procedure>&rolestep.sgm;<step id="sysresacctsetup-step-37"><para>Edit the <literal>adm</literal> <filename>crontab</filename> file to stop the <filename>ckpacct</filename>, <filename>runacct</filename>, and <filename>monacct</filename> programs from running by commenting
out the appropriate lines.</para><screen># <userinput>EDITOR=vi; export EDITOR</userinput>
# <userinput>crontab -e adm</userinput>
#0 * * * * /usr/lib/acct/ckpacct
#30 2 * * * /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log
#30 7 1 * * /usr/lib/acct/monacct</screen>
</step><step id="sysresacctsetup-step-38"><para>Edit the <literal>root crontab</literal> file
to stop the <filename>dodisk</filename> program from running by commenting
out the appropriate line.</para><screen># <userinput>crontab -e</userinput>
#30 22 * * 4 /usr/lib/acct/dodisk</screen>
</step><step id="sysresacctsetup-step-39"><para>Stop the system accounting program.</para><screen># <userinput>/etc/init.d/acct stop</userinput></screen>
</step><step id="sysresacctsetup-step-49"><para>(Optional) Remove the newly added
comment symbols from the <filename>crontab</filename> files.</para>
</step><step><para>Restart the system accounting program to re-enable system accounting.</para><screen># <userinput>/etc/init.d/acct start</userinput></screen>
</step>
</procedure>
</task><task id="sysresacctsetup-41703"><title>How to Permanently Disable System
Accounting</title><procedure>&rolestep.sgm;<step id="sysresacctsetup-step-42"><para>Edit the <literal>adm</literal> <filename>crontab</filename> file and delete the entries for the <command>ckpacct</command>, <command>runacct</command>, and <command>monacct</command> programs.</para><screen># <userinput>EDITOR=vi; export EDITOR</userinput>
# <userinput>crontab -e adm</userinput></screen>
</step><step id="sysresacctsetup-step-43"><para>Edit the <literal>root</literal> <filename>crontab</filename> file and delete the entries for the <command>dodisk</command> program.</para><screen># <userinput>crontab -e</userinput></screen>
</step><step id="sysresacctsetup-step-44"><para>Remove the startup script for Run
Level 2. </para><screen># <userinput>unlink /etc/rc2.d/S22acct</userinput></screen>
</step><step id="sysresacctsetup-step-45"><para>Remove the stop script for Run Level
0.</para><screen># <userinput>unlink /etc/rc0.d/K22acct</userinput></screen>
</step><step id="sysresacctsetup-step-46"><para>Stop the system accounting program.</para><screen># <userinput>/etc/init.d/acct stop</userinput></screen>
</step>
</procedure>
</task>
</sect1>
</chapter>