Setting Up System Accounting
You can set up system accounting to run while the system is in multiuser mode (system state 2). Generally, this task involves:
Creating the /etc/rc0.d/K22acct and /etc/rc2.d/S22acct startup scripts
Modifying the /var/spool/cron/crontabs/adm and /var/spool/cron/crontabs/root crontab files
The following table describes the default accounting scripts.
Table 19-2 Default Accounting Scripts
Accounting Script | Man Page | Purpose | Run Frequency |
---|---|---|---|
ckpacct | ckpacct(1M) | Checks the size of the /usr/adm/pacct log file and makes sure it does not get too large. | Periodically |
runacct | runacct(1M) | Processes connect, disk, and fee accounting information. You can remove the commands from this script for the accounting features you do not want processed. | Daily |
monacct | monacct(1M) | Generates fiscal accounting summary reports on a monthly basis. You can determine how often this script is run. You can remove the commands from this script for the accounting features you do not want generated. | On a fiscal basis |
You can choose which accounting scripts run by default. After these entries have been added to the crontab files, accounting should run automatically.
How to Set Up System Accounting
Become superuser.
If necessary, install the SUNWaccr and SUNWaccu packages on your system by using the pkgadd command.
Install /etc/init.d/acct as the startup script for Run Level 2.
# ln /etc/init.d/acct /etc/rc2.d/S22acct
Install /etc/init.d/acct as the stop script for Run Level 0.
# ln /etc/init.d/acct /etc/rc0.d/K22acct
Add the following lines to the adm crontab file to start the ckpacct, runacct, and monacct scripts automatically.
# EDITOR=vi; export EDITOR # crontab -e adm 0 * * * * /usr/lib/acct/ckpacct 30 2 * * * /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log 30 7 1 * * /usr/lib/acct/monacct
Add the following line to the root crontab file to start the dodisk script automatically.
# crontab -e 30 22 * * 4 /usr/lib/acct/dodisk
Edit /etc/acct/holidays to include national and local holidays.
For more information, see holidays(4) and the example that follows.
Reboot the system, or start accounting manually by typing:
# /etc/init.d/acct start
Examples--Setting Up Accounting
This modified adm crontab contains entries for the ckpacct, runacct, and monacct scripts.
#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 |
This modified root crontab contains entries for the dodisk program.
#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. # # The rtc command is run to adjust the real time clock if and when # daylight savings time changes. # 10 3 * * * /usr/sbin/logadm 15 3 * * 0 /usr/lib/fs/nfs/nfsfind 1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1 30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean 30 22 * * 4 /usr/lib/acct/dodisk |
The following example shows a sample /etc/acct/holidays file.
* @(#)holidays January 1, 2001 * * Prime/Nonprime Table for UNIX Accounting System * * Curr Prime Non-Prime * Year Start Start * 1999 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 |
Billing Users
If you provide special user services by request, such as restoring files or remote printing, you might want to bill users by running the chargefee utility. The chargefee utility records charges in the /var/adm/fee file. Each time the runacct utility is executed, new entries are merged into the total accounting records.
See acctsh(1M) for more information.
How to Bill Users
Charge a user for special services.
# /usr/lib/acct/chargefee username amount
username
User account you want to bill.
amount
Number of units to bill the user. This is an arbitrary unit that you set to charge users based on some task like printing or restoring a file. You would have to write a script that invokes chargefee and charges a user for a specific task.
Example--Billing Users
The following example charges the user print_customer 10 units.
# /usr/lib/acct/chargefee print_customer 10 |
Maintaining Accounting Information
This section describes how to fix corrupted accounting files and how to restart the runacct script.