By using the accounting services, you can obtain accounting information for the following:
You can set up accounting so that information is collected automatically on a periodic basis. You can also manually invoke accounting shell scripts and commands to obtain accounting information when you need it.
The accounting database files are located in the /var/adm directory and include the following files:
File | Description |
---|---|
wtmp | The login/logout history file |
utmp | The active connect session file |
pacct | The active process accounting file |
dtmp | The disk usage file |
The accounting scripts and commands access the records in the accounting database files and reformat them so that you can use the records for purposes such as archiving, diagnostic analysis, or resource billing.
The various accounting shell scripts and commands also can do the following:
You can redirect or pipe script and command output to files or to other scripts and commands.
System accounting allows you to distinguish between prime time and nonprime time. The system is used most during prime time and least during nonprime time. System use during nonprime time can be assessed at a lower rate than system use during prime time. You specify the period of nonprime time in the /usr/sbin/acct/holidays database file. Usually, if enabled, automatic accounting is performed during nonprime time.
Name | Type | Description |
---|---|---|
ac | Command | Displays connect session records. |
acctcms | Command | Formats the binary command usage summary files. |
acctcom | Command | Displays process accounting record summaries from the default pacct database file or a specified file. |
acctcon1 | Command | Summarizes the records in the wtmp file in ASCII format. |
acctcon2 | Command | Summarizes the contents of the files formatted by the acctcon1 command. |
acctdisk | Command | Performs comprehensive disk usage accounting. |
acctdusg | Command | Performs disk block usage accounting. |
acctmerg | Command | Merges accounting record files. |
accton | Command | Turns on process accounting. |
acctprc1 | Command | Displays records of acct type structure by user identification number and login name. |
acctprc2 | Command | Displays records of acct type structure by user identification number and full name. |
acctwtmp | Command | Writes records to the /var/adm/wtmp file. |
chargefee | Script | Writes a charge-fee record to the /var/adm/fee database file. |
ckpacct | Script | Checks the size of the /var/adm/pacct active binary process accounting file to ensure that it is not too large. |
diskusg | Command | Performs disk accounting according to user identification number. |
dodisk | Script | Writes daily disk usage accounting records to the /var/adm/nite/dacct disk usage accounting database file. |
fwtmp | Command | Displays the /var/adm/wtmp binary file records in ASCII format, allowing you to fix errors. |
last | Command | Displays login information. |
lastcomm | Command | Displays information about commands that were executed. |
lastlogin | Script | Writes the date of the last login for all users to the /var/adm/acct/sum/loginlog file. |
monacct | Script | Creates monthly summary accounting report files. |
nulladm | Script | Creates files that are owned by the adm user and group and that have 664 permission. |
pac | Command | Displays printer accounting records. |
prctmp | Script | Displays the /var/adm/acct/nite/ctmp connect session record file. |
prdaily | Script | Collects and displays daily accounting records from various files. |
printpw | Command | Displays the contents of the /etc/passwd file. |
prtacct | Script | Formats in ASCII and displays a tacct daily accounting file. |
remove | Script | Removes any /var/adm/acct/sum/wtmp*, /var/adm/acct/sum/pacct*, and /var/adm/acct/nite/lock* files. |
runacct | Script | Invokes the daily accounting processes. This command periodically calls various accounting commands and shell scripts to write information to various accounting files. |
sa | Command | Displays a summary of accounting records. |
shutacct | Script | Turns off accounting. |
startup | Script | Enables accounting processes. |
turnacct | Script | Controls the creation of process accounting files. |
wtmpfix | Command | Corrects date and time stamp inconsistencies in the /var/adm/wtmp file. |
You should ensure that the accounting files, particularly those in binary format, do not become too large. Some extraneous files are produced by the accounting commands and shell scripts, but in general these files are temporary and exist only while the process is running. Under some circumstances (if a process terminates prematurely, for example), one or more temporary files can appear in one of the /var/adm subdirectories. You should check these subdirectories periodically and remove the unnecessary files.
Accounting files can become corrupted or lost. The files that are used to produce daily or monthly reports, such as the /var/adm/wtmp and /var/adm/acct/sum/tacct accounting database files, must have complete integrity. If these files are corrupted or lost, you can recover them from backups. In addition, you can use the fwtmp or the wtmpfix command to correct the /var/adm/wtmp file. Refer to Section 13.4.2 and Section 13.4.1 for more information. You can use the acctmerg command to fix errors in the /var/adm/acct/sum/tacct file. Refer to Section 13.9.2 for more information.
The /var/adm/acct/nite directory contains files that are reused daily by the runacct script. Some of these files have binary counterparts in the /var/adm/acct/sum directory, which contains the cumulative summary files that are updated by the runacct shell script and used by the monacct shell script to produce monthly reports.
Table 13-2 to Table 13-5 list the accounting files. The Name column specifies the file name and the table title specifies the directory pathname for the files. The Type column tells you if the file is an ASCII file or a binary file. The Description column provides a description of the file.
Name | Type | Description |
---|---|---|
dtmp | ASCII | Contains temporary output produced by the dodisk shell script. |
fee | ASCII | Contains output from the chargefee shell script. |
pacct | Binary | Specifies the active process accounting database file. If a process is called by a user, another process, or a script file, process information is written to this file. |
pacctn | Binary | Specifies the alternate pacct file created by the turnacct switch command. The pacct database file becomes large quickly if a system has many users. A single pacct file is limited to 500 1024-block disk spaces. The size of these files is monitored by the runacct shell script. Each time a new pacctn file is created, the value n is incremented by one. |
qacct | Binary | Contains queueing (printer) system accounting records. This file is used by the runacct shell script. |
savacct | Binary | Specifies the file used by the sa command to store system process accounting summary records. |
Spacctn.mmdd | Binary | Specifies the pacctn files produced by the runacct shell script for the month and day specified by mm and dd, respectively. |
usracct | Binary | Specifies the file used by the sa command to store user process accounting summary records. |
utmp | Binary | Specifies the active connect session accounting database file, which is written to if a user calls a process that produces a connect session. |
wtmp | Binary | Specifies the cumulative login/logout accounting database file. If a user logs in to the system, connect time and user information is written to this file. |
Name | Type | Description |
---|---|---|
active | ASCII | Specifies the daily runacct shell script progress file. When the runacct shell script executes, information about its progress is written to this file. This file also contains error and warning messages. |
activemmdd | ASCII | Specifies the daily runacct shell script error file for the month and day specified by mm and dd, respectively. This file is similar to the active file. |
cklock | ASCII | Specifies the file the ckpacct shell script uses to ensure that more than one runacct shell script is not called during any 24-hour period. This file is removed each day if the runacct shell script has completed. |
cms | ASCII | Specifies the active total daily command summary file. This file is the ASCII version of the /var/adm/acct/sum/cms file. This file is created by the acctcms command, which is called by the runacct shell script to rewrite the /var/adm/acct/sum/cms file records. The monacct shell script initializes this file. |
ctacct.mmdd | Binary | Specifies the connect accounting records in tacct.h format that are obtained from the connect session accounting records for the month and day specified by mm and dd, respectively. This file is temporary and is deleted after the daytacct file records are written for each accounting period. |
ctmp | ASCII | Specifies the temporary login/logout record file. This file contains the output of the acctcon1 accounting command, which is called by the runacct shell script to rewrite the wtmp file records. |
daycms | ASCII | Specifies the daily command summary file. This file is the ASCII version of the /var/adm/acct/sum/daycms binary file. The runacct shell script calls the prdaily shell script, which invokes the acctcms command to create the file. |
daytacct | Binary | Contains the total accounting records in tacct.h format for the previous day. |
dacct | Binary | Contains the weekly total disk usage accounting records when the acctdisk command is called by the dodisk shell script. |
lastdate | ASCII | Specifies the last day that the runacct shell script was executed. |
lineuse | ASCII | Contains terminal (tty) line connect times. This file provides line use statistics for each terminal line used during the previous accounting period. |
lock | ASCII | Specifies the file used to ensure that the cron daemon does not call the runacct shell script more than once during any 24-hour period. This file is removed each day when the runacct shell script has completed. |
log | ASCII | Contains diagnostic output that is produced when the runacct script invokes the acctcon1 command. |
owtmp | Binary | Specifies the daily wtmp file after a correction by the wtmpfix command. |
ptacctn.mmdd | Binary | Specifies the additional daily pacctn files for the month and day specified by mm and dd, respectively. These files are created if the daily pacct process accounting file requires more than 500 disk blocks. |
reboots | ASCII | Contains a list of system reboots during the previous accounting period. |
statefile | Binary | Specifies the final runacct shell script execution state. |
wtmp.mmdd | Binary | Specifies the fixed daily login/logout accounting database file for the month and day specified by mm and dd, respectively. Connect session records of users who logged in to the system during the previous day are written to this file. |
wtmperror | ASCII | Contains any error messages produced when a wtmp file is fixed during the execution of the wtmpfix command. |
wtmperrormmdd | ASCII | Contains any error messages produced when the runacct shell script detects an error during execution of the wtmpfix command for the month and day specified by mm and dd, respectively. |
Name | Type | Description |
---|---|---|
cms | Binary | Specifies the active total command summary file. When the runacct shell script is executed, records are written to this file to obtain the total command summary file. |
cmsprev | Binary | Specifies the previous day's /var/adm/acct/sum/cms file. |
daycms | Binary | Specifies the previous day's command summary file. When the runacct shell script is executed, monthly command summary records for the previous day are written to this file. |
loginlog | ASCII | Contains a list of the last monthly login date for each user name. |
rprtmmdd | ASCII | Specifies the daily accounting report for the month and day specified by mm and dd, respectively. |
tacct | Binary | Specifies the cumulative total accounting file. This file is the total daily accounting file for system use. It is updated on a daily basis by the runacct shell script. |
tacctmmdd | Binary | Specifies the total accounting file for the month and day specified by mm and dd, respectively. |
tacctprev | Binary | Specifies the previous day's tacct file. This file is the tacct binary file for the previous accounting period. |
Name | Type | Description |
---|---|---|
cmsmm | Binary | Specifies the active command summary file for the month specified by mm. |
fiscrptmm | ASCII | Specifies the accounting report for the month specified by mm. |
tacctmm | Binary | Specifies the cumulative total accounting file. This file is the total accounting file for system use. It is updated on a monthly basis by the monacct shell script. |
You must install the System Accounting Utilities subset to use accounting. Note
To obtain accounting information for all the machines in a network, you should set up accounting on a single machine. Use the following procedure to enable system accounting. The sections that follow describe these steps in detail.
Resource accounting is discussed separately from printer accounting because the print driver software uses different servers, daemons, and routines. Setting up printer accounting is described in Chapter 11.
ACCOUNTING="YES"
You can use the rcmgr command to set the variable, as follows:
# rcmgr set ACCOUNTING YES
You can start accounting without rebooting your system by using the startup command. Refer to Section 13.3 for more information.
If the /usr/sbin/acct/holidays file does not exist, you must create it. If the file exists, you must edit it to reflect your accounting needs.
You can set the NHOLIDAYS environment variable to specify the maximum number of holidays that you can include in the holidays file.
You can include the following commands and shell scripts in the /usr/spool/cron/crontabs/adm file:
You can include the dodisk shell script in the /usr/spool/cron/crontabs/root file. The dodisk shell script creates disk usage accounting records and should be run once during nonprime time each week.
Refer to Chapter 4 and to the crontab
(1)
reference page for more information on submitting commands with the crontab command.
0 2 * * 1-6 /usr/sbin/acct/runacct > /usr/adm/acct/nite/fd2log& 5 * * * * /usr/sbin/acct/ckpacct& 0 4 1 * * /usr/sbin/acct/monacct& 10 3 * * * /usr/sbin/ac -p > /var/adm/timelog& 40 2 * * * /usr/sbin/pac -s&
0 3 * * 4 /usr/sbin/acct/dodisk > /var/adm/diskdiag&
The startup shell script initializes the accounting functions and has the following syntax:
You must ensure that the /var/adm/pacct file, which is created by the startup script, is owned by group adm and user adm and has 664 protection. If it does not have the correct ownership, the accton command will not work, and the following message will be displayed: Note
accton: uid/gid not adm
The shutacct script turns process accounting off and ensures that the accounting functions are halted before the system shuts down. The shutacct shell script has the following syntax:
/usr/sbin/acct/shutacct[Reason]
Connect session commands can convert the /var/adm/wtmp file records to useful connect session accounting records. You can obtain connect session accounting only if the /var/adm/wtmp file exists.
The formatted records in the /var/adm/wtmp file provide the following information about each connect session:
You can use the following two shell scripts and seven commands to obtain or modify information about system connect sessions:
Command | Description |
---|---|
ac | This command displays connect session records for the entire system and for each user. |
acctcon1 | This command summarizes connect session records and displays those records in ASCII format, using one line for each connect session. |
acctcon2 | This command uses the output of the acctcon1 command to produce an accounting record file of the total connect session in ASCII format. |
acctwtmp | This command enables you to write records to the wtmp file by entering them from the keyboard. |
fwtmp | This command displays records from files with the utmp.h file structure. |
last | This command displays login information. |
lastlogin | This shell script updates the /var/adm/acct/sum/loginlog file to show the last date that each user logged in. |
prctmp | This shell script displays the contents of the session-record file (usually /var/adm/acct/nite/ctmp) that the acctcon1 command created. |
wtmpfix | This command corrects the wtmp connect session records that are affected by a date modification and validates login names written to the login name field in the wtmp file. |
The /usr/include/utmp.h header file structure is the record format for the following connect session files:
The /usr/include/utmp.h header file structure includes nine fields. Table 13-6 shows the utmp ASCII conversion format for the field number, member name in the header file structure, its description and, if necessary, character length.
Field | Member | Description |
---|---|---|
1 | ut_user | The user login name, which must have exactly sizeof(ut_user) characters. |
2 | ut_id | The inittab ID, which must have exactly sizeof(ut_id) characters. |
3 | ut_line | A memory location, where information used to describe the type of record (for example, the device name) is stored. It must have exactly sizeof(ut_line) characters. |
4 | ut_pid | The process identification number. |
5 | ut_type | The type of entry, which can specify several symbolic constant values. The symbolic constants are defined in the /usr/include/utmp.h header file. |
6 | ut_exit.e_termination | The process termination status. |
7 | ut_exit.e_exit | The process exit status. |
8 | ut_time | The starting time (in seconds). |
9 | ut_host | The host name, which must have exactly sizeof(ut_host) characters. |
The /usr/sbin/acct/wtmpfix command corrects date and time stamp inconsistencies in files with the utmp.h header file structure and displays the records. The runacct script invokes the wtmpfix command.
Each time a date is entered in the /var/adm/wtmp file (for example, at system startup or by using the date command), a pair of date-change records is also written to the wtmp file. The first date-change record is the old date, which is specified in the ut_line and ut_type fields. The second date-change record is the new date, which is also specified in the ut_line and ut_type fields. The wtmpfix command uses these records to synchronize all date and time stamps in the /var/adm/wtmp file, and then the date-change record pair is removed. The date-change records never appear in an output file.
The wtmpfix command also checks the validity of the user name field (the ut_user field) to ensure that the name consists only of alphanumeric characters, a dollar sign ($), or spaces. If an invalid name is detected, the wtmpfix command changes the login name to INVALID and displays a diagnostic message.
The wtmpfix command has the following syntax:
/usr/sbin/acct/wtmpfix[filename]. . .
The filename variable specifies the name of the input file. The default input file is the /var/adm/wtmp binary file.
During system operation, date changes and reboots occur, and the records are written to the /var/adm/wtmp file. The wtmpfix command adjusts the time stamps in the /var/adm/wtmp file; however, some corrections can evade detection by the wtmpfix command and cause the acctcon command to fail. In this case, you can correct the /var/adm/wtmp file by using the fwtmp command.
The fwtmp command has the following syntax:
The fwtmp file uses standard input, or you can direct a file to the command.
If you want to enter /usr/include/utmp.h header file records manually, you must enter data in each of the nine fields in the order used by the utmp ASCII structure members, as shown in Table 13-6. All record-field entries that you enter from the keyboard must be separated by a space. Also, you must specify all the string fields by using blank characters, if necessary, up to the maximum string size. All decimal values must be specified with the required number of decimal places, using preceding 0s (zeros) to indicate the empty digit positions.
The following example converts the /var/adm/wtmp binary file records to ASCII records:
# /usr/sbin/acct/fwtmp < /var/adm/wtmp system boot 0 20000 0000 652547412 Jan 5 11:10:12 1994 system boot 0 10062 0123 652547412 Jan 5 11:10:12 1994 bcheck bl 6 80000 0000 652547413 Jan 5 11:10:13 1994 cat cr 16 80000 0000 652547414 Jan 5 11:10:14 1994 rc rc 17 80000 0000 652547485 Jan 5 11:11:25 1994 hoffman co console 147 70000 0001 652547495 Jan 5 11:11:35 1994 hoffman p4 pty/ttyp4 2156 80000 0002 652650095 Jan 6 15:41:35 1994 LOGIN p4 pty/ttyp4 2140 60000 0000 652649075 Jan 6 15:24:35 1994 LOGIN p4 pty/ttyp4 2140 80000 0000 652649086 Jan 6 15:24:46 1994
To correct a /var/adm/wtmp file:
# fwtmp < wtmp.0617 > wtmp_temp
# fwtmp -ic < wtmp_temp > wtmp.0617
The acctwtmp command has the following syntax:
/usr/sbin/acct/acctwtmpreason
The reason variable must have a maximum of sizeof(ut_line) characters and be enclosed in quotation marks (" ").
The ac command has the following syntax:
/usr/sbin/ac[-d] [-p] [-w filename] [username . . .]
Refer to the ac
(8) reference page for information on command options.
The default behavior displays the sum of the system connect time for all users. For example:
# /usr/sbin/ac "total 48804.26"
The following command displays the total connect time according to user name:
# /usr/sbin/ac -p buckler 61.44 fujimori 530.94 newsnug 122.38 dara 0.10 root 185.98 buchman 339.33 russell 53.96 hoff 200.43 hermi 157.81 total 1968.02
The total connect time for all users listed is shown in the last line.
The acctcon1 command has the following syntax:
/usr/sbin/acct/acctcon1[-l file] [ -o file] [-pt]
You must direct a file as input to the command. Refer to the acctcon1
(8)
reference page for information on command options.
The following command line provides an example of a /var/adm/acct/nite/lineuse file. It writes records to the specified file in ASCII line-usage format, which helps you to track line usage and to identify bad lines; and it includes the reference designation of the ports that the user logged in to and the date and time stamp of the currently active connect session.
# acctcon1 -l line_file < /var/adm/wtmp | more line_file TOTAL DURATION IS 57 MINUTES LINE MINUTES PERCENT # SESS # ON # OFF pty/ttyp4 37 64 3 3 7 console 26 45 2 2 4 pty/ttyp5 7 11 1 1 3 pty/ttyp6 0 0 0 0 2 TOTALS 69 - 6 6 16
In the previous example, the ASCII line-usage format specifies the following:
The following example produces a sample /var/adm/acct/reboots file. It writes records to a file in ASCII overall-record format, which specifies a starting time, an ending time, the number of restarts, and the number of date changes.
# acctcon1 -o overall_file < /var/adm/wtmp | more overall_file from Thu Jan 13 17:20:12 1994 EDT to Fri Jan 14 09:56:42 1994 EDT 2 date changes 2 acctg off 0 run-level S 2 system boot 2 acctg on 1 acctcon1
The overall-record format includes the from and to fields, which specify the time that the last accounting report was generated and the time of the current report. These fields are followed by a list of records from the /var/adm/wtmp file.
/usr/sbin/acct/prctmp[filename]
Refer to the prctmp
(8) reference page for more information.
The runacct shell script invokes the lastlogin shell script during its CMS state. You can invoke the lastlogin shell script manually to update the /var/adm/acct/sum/loginlog file, which is included in the /var/adm/acct/sum/rprtmmdd daily report.
The lastlogin shell script has the following syntax:
/usr/sbin/acct/lastlogin
The following information is included when applicable:
The last command has the following syntax:
/usr/bin/last[-#] [username . . .] [tty . . .]
By default, all records are displayed. You can specify a user name and a terminal for which you want to display records.
The following example displays information only about the three previous root logins:
# last -3 root root ttyp1 shout Fri Jan 21 10:56 still logged in root ttyp1 raven Fri Jan 21 08:59 - 09:00 (00:00) root ttyp0 raven Thu Jan 20 15:29 - 15:54 (00:24)
The /var/adm/pacct file will grow in size. The ckpacct command checks the size of the /var/adm/pacct file and creates a /var/adm/pacctn file if the pacct file is larger than a specified size.
The /var/adm/pacct database file includes the following process information:
The record format for the process accounting files is tacct format and is established by the acct header file structure. The acct header file structure is defined in the /usr/include/sys/acct.h header file and includes up to 18 columns of accounting information. The tacct structure members are defined in the private tacct.h header file.
Table 13-7 specifies the column number, heading, and description for files with the tacct format.
Column | Heading | Description |
---|---|---|
1 | UID | Specifies the user identification number, which is obtained from the /etc/passwd file. |
2 | LOGNAME | Specifies the user login name, which is obtained from the /etc/passwd file. |
3 | PRI_CPU | Specifies the prime time CPU run time, which is the total time (in seconds) that prime time CPU run time was charged to the user. |
4 | NPRI_CPU | Specifies the nonprime time CPU run time, which is the total time (in seconds) that nonprime time CPU run time was charged to the user. |
5 | PRI_MEM | Specifies the prime time memory kcore minutes, which is the total CPU time (in minutes) multiplied by the mean size of the memory used. |
6 | NPRI_MEM | Specifies the nonprime time memory kcore minutes, which is the total CPU time (in minutes) multiplied by the mean size of the memory used. |
7 | PRI_RD/WR | Specifies the total number of characters transferred during prime time operation. |
8 | NPRI_RD/WR | Specifies the total number of characters transferred during nonprime time operation. |
9 | PRI_BLKIO | Specifies the total number of I/O blocks transferred during prime time read and write operations. The number of bytes in an I/O block depends on how it was implemented. |
10 | NPRI_BLKIO | Specifies the total number of I/O blocks transferred during nonprime time read and write operations. The number of bytes in an I/O block depends on how it was implemented. |
11 | PRI_CONNECT | Specifies the total number of prime time seconds that a connection existed. |
12 | NPRI_CONNECT | Specifies the total number of nonprime time seconds that a connection existed. |
13 | DSK_BLOCKS | Specifies the total number of disk blocks used. |
14 | Specifies the total number of pages queued to any printer in the system. | |
15 | FEES | Specifies the number of units charged. This value is specified with the /usr/sbin/acct/chargefee shell script. |
16 | PROCESSES | Specifies the total number of processes spawned by the user during the accounting period. |
17 | SESS | Specifies the total number of times the user logged in during the accounting period. |
18 | DSAMPS | Specifies the total number of times that the disk accounting command was used to get the total number of disk blocks specified in the DSK_BLOCKS column. You can divide the value in the DSK_BLOCKS column by the value in the DSAMPS column to obtain the average number of disk blocks used during the accounting period. |
/usr/sbin/acct/accton[filename]
If you do not specify the filename variable, process accounting is disabled. If you specify the filename variable, process accounting is turned on and the kernel writes process accounting records to the specified file. Usually, this file is the /var/adm/pacct file; however, you can specify a different process accounting database file. The file must exist in the /var/adm directory, be owned by user adm, and be a member of the adm login group.
The runacct and turnacct shell scripts use the /var/adm/pacct process accounting database file. If you specify a process accounting database file other than the /var/adm/pacct file, the runacct and turnacct shell scripts will be affected. Note
turnacct[on | off | switch ]
The turnacct on shell script turns on process accounting by invoking the accton shell script with the /var/adm/pacct file argument.
The turnacct off shell script turns off process accounting by invoking the accton command without an argument to disable process accounting.
The turnacct switch shell script moves the contents of the /var/adm/pacct file to the /var/adm/pacctn file and then creates a new /var/adm/pacct file.
You can set up your cron daemon to invoke the ckpacct script periodically. Refer to Section 13.2.4 for more information.
The ckpacct shell script has the following syntax:
ckpacct[blocksize]
The blocksize variable specifies the size limit (in disk blocks) for the /var/adm/pacct file. The default size is 500 disk blocks.
If you invoke the ckpacct shell script, the script checks the number of disk blocks that are available in the /var/adm directory. If the number of available blocks is less than the size limit, process accounting is disabled by invoking the turnacct off shell script. A diagnostic message is displayed and mailed to the address that is specified with the MAILCOM environment variable. Use the putenv function to set the MAILCOM environment variable to the following command:
mail root adm
The following diagnostic message shows that there are 224 disk blocks remaining in the /var/adm directory:
ckpacct: /var/adm too low on space (224 blocks) "turning acctg off"
The ckpacct shell script continues to display diagnostic messages until adequate space exists in the /var/adm directory.
The acctcom command displays information only about processes that have terminated; use the ps command to display information about active processes. The acctcom command has the following syntax:
/usr/bin/acctcom[option . . .] [filename . . .]
If you do not specify the filename variable, the command uses the /var/adm/pacct file to obtain the process accounting records. You can use the filename variable to specify a different process accounting file that has the acct.h header file structure. If you specify more than one filename variable, the acctcom command reads the files in chronological order.
If you do not specify any command options, the default output includes the following information in a column heading format:
Refer to the acctcom
(8) reference page for information on the command
options.
The following is an example of the default process accounting summary output:
# /usr/bin/acctcom /var/adm/pacct1 ACCOUNTING RECORDS FROM: Mon Jan 17 02:00:00 1994 COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) #sa root ttyp1 11:59:00 11:59:00 0.77 0.01 0.00 ls root ttyp1 11:59:04 11:59:04 0.11 0.01 0.00 uugetty root ? 11:58:39 11:59:48 69.53 0.01 0.00 #ls root ttyp1 11:59:55 11:59:55 0.30 0.01 0.00 uugetty root ? 11:59:49 12:00:58 69.48 0.01 0.00 cp adm ? 12:05:01 12:05:01 0.33 0.01 0.00 chmod adm ? 12:05:01 12:05:01 0.27 0.01 0.00 #df adm ? 12:05:02 12:05:02 0.38 0.01 0.00 awk adm ? 12:05:02 12:05:02 0.58 0.01 0.00 sed adm ? 12:05:02 12:05:02 0.56 0.01 0.00
/usr/sbin/sa[options . . .] [filename]
The filename variable specifies a process accounting file with the acct.h header file structure. If the filename variable is not specified, the /var/adm/pacct file is used.
If you invoke the sa command with no options, the
default output consists of six unheaded columns. Certain command options allow
you to expand the six columns to include more information. You can specify
options to change the format and to output additional information that includes
an identifying suffix. Refer to the sa
(8) reference page for information on
the command options.
The following example shows the default format of the output of the sa command:
# /usr/sbin/sa 798 277.24re 0.08cpu 3248790avio 0k 7 33.42re 0.08cpu 103424avio 0k csh 14 0.08re 0.00cpu 127703avio 0k mv 40 0.34re 0.00cpu 159968avio 0k cp 2 0.01re 0.00cpu 132448avio 0k acctwtmp 34 0.13re 0.00cpu 133517avio 0k chmod 23 0.10re 0.00cpu 139136avio 0k chgrp 25 0.11re 0.00cpu 144768avio 0k chown 36 0.15re 0.00cpu 133945avio 0k dspmsg 32 0.18re 0.00cpu 134206avio 0k cat [1] [2] [3] [4] [5] [6]
The following example adds three columns to the default format to display the following percentages:
# /usr/sbin/sa -c 645 100.00% 324.10re 100.00% 0.02cpu 100.00% 6171050avio 0k 2 0.31% 25.70re 7.93% 0.02cpu 100.00% 107392avio 0k csh 6 0.93% 0.04re 0.01% 0.00cpu 0.00% 132928avio 0k mv 38 5.89% 0.33re 0.10% 0.00cpu 0.00% 163357avio 0k cp 2 0.31% 0.01re 0.00% 0.00cpu 0.00% 132992avio 0k cat 26 4.03% 0.11re 0.03% 0.00cpu 0.00% 136832avio 0k chmod 24 3.72% 0.10re 0.03% 0.00cpu 0.00% 139824avio 0k chgrp [1] [2] [3]
The additional columns show the following information:
The runacct shell script invokes the acctcms command during its CMS state. You can also invoke this command manually to create a command summary report.
The acctcms command has the following syntax:
/usr/sbin/acct/acctcms[-acjnopst] filename . . .
If you invoke the acctcms command with no options, the command sorts the output in descending order according to total kcore minutes, which is the number of kilobytes of memory used by the process multiplied by the buffer time used. Binary output is the default. Use the following calculation to obtain the kcore minutes:
kcoremin=[(CPU time in seconds)*(mean memory size in kbyte)]/60Refer to the
acctcms
(8) reference page for information on
the command options.
If you use the acctcms command to produce a total summary file in ASCII format, each command record will consist of more than 80 characters, and the entire width of 8.5 x 11-inch paper could be used if the 10-character per inch constant-width font is specified. If part of a record exceeds the column width, it is moved to the next line. Note
The following example produces ASCII output that includes the statistics for commands that were invoked only once in a row specifying ***other in the COMMAND NAME column:
# acctcms -a -j /var/adm/pacct1 TOTAL COMMAND SUMMARY COMMAND NUMBER TOTAL TOTAL TOTAL MEAN MEAN HOG CHARS BLOCKS NAME CMDS KCOREMIN CPUMIN REALMIN SIZEK CPUMIN FACTOR TRNSFD READ TOTALS 9377 0.00 0.36 26632.67 0.00 0.00 0.00 17768213 100529 chmod 34 0.00 0.00 .15 0.00 0.00 0.07 5785856 64 ln 4 0.00 0.00 0.01 0.00 0.00 0.78 422016 16 xterm 9 0.00 0.03 537.41 0.00 0.00 0.00 22948288 536 getcons 8 0.00 0.00 0.14 0.00 0.00 0.07 26636992 102 cfe2.20 4 0.00 0.00 0.09 0.00 0.00 0.12 182464 155 dump 22 0.00 0.00 14.91 0.00 0.00 0.00 69402112 128 whoami 4 0.00 0.00 0.03 0.00 0.00 0.36 7405952 27 restore 40 0.00 0.00 49.16 0.00 0.00 0.00 34247488 1316 ***other 25 0.00 0.00 3546.88 0.00 0.00 0.00 35904984 737 hostname 2 0.00 0.00 0.01 0.00 0.01 0.94 223104 14The hog factor is the total CPU time divided by the total real time.
If your system has users with the same user identification number, you should use a process accounting file in the /var/adm/acct/nite directory instead of the /var/adm/pacct file.
The runacct shell script invokes the acctprc1 command during its PROCESS state. You can also invoke the command manually. The acctprc1 command has the following syntax:
/usr/sbin/acct/acctprc1[filename]
The filename variable specifies a file that contains a list of login sessions in a format defined by the /usr/include/utmp.h header file structure. If the filename variable is not specified, login names are obtained from the /etc/passwd file.
The command output specifies information in a format with seven unheaded columns that specify the following:
The following is an example of the acctprc1 command and its output:
# /usr/sbin/acct/acctprc1 < /usr/adm/pacct 0 root 0 1 17228 172 6 4 adm 0 6 46782 46 16 0 root 0 22 123941 132 28 9261 hoffmann 6 0 17223 22 20 9 lp 2 0 20345 27 11 9261 hoffmann 0 554 16554 20 234
The runacct shell script invokes the acctprc2 command during its PROCESS state. You can also invoke the command manually.
The following information is displayed for each process:
The lastcomm command has the following syntax:
/usr/bin/lastcomm[command] [username] [tty]
The following example displays information about the sed commands executed by root:
# lastcomm sed root sed S root ttyp0 0.01 secs Fri Jan 21 11:34 sed S root ttyp0 0.01 secs Fri Jan 21 11:34
You can combine the total accounting information in the /var/adm/acct/nite/dacct file with other accounting information to create complete accounting reports. For example:
# /usr/sbin/acct/dodisk # /usr/sbin/acct/prtacct /var/adm/acct/nite/dacct
/usr/sbin/acct/dodisk[-o] [filesystem . . .]
/usr/sbin/acct/dodisk[device special file . . .]
Using the -o option, you can specify the file system variable to perform disk usage accounting on the mount point of a UFS file system or an AdvFS fileset. If the -o option is not specified, the variable must be the raw or character device special file. For example:
# /usr/sbin/acct/dodisk /dev/rrz3cIf you do not specify any arguments, disk accounting is performed on the UFS device special files decribed in the /etc/fstab database file. Refer to the
fstab
(4)
reference page for more information.
If you have a swap space specified in the /etc/fstab file, the dodisk shell script will not execute correctly. In this case, you can edit the dodisk shell script to use only specific file systems or you can invoke the dodisk shell script and specify the file systems for which you want accounting. Note
If you specify the -o option, the dodisk shell script uses the acctdusg command instead of the diskusg command to perform a more thorough but slower version of disk accounting. If you specify the -o option and a filesystem variable, specify the mount point instead of the device special file name.
/usr/sbin/acct/diskusg[-options] [filesystems]
Refer to the diskusg
(8) reference page for information on the command
options.
The diskusg command produces ASCII output, which is directed to the /var/adm/dtmp file. This file is used as input to the acctdisk command, which converts the ASCII records to binary total accounting records in the /var/adm/acct/nite/dacct file. You can merge these records with other accounting records to create a daily total accounting report.
Each output record produced by the diskusg command contains the user identification number, login name, and the total number of disk blocks allocated to the user. Because the diskusg command checks user inode records, all disk space is accounted for, including empty directories.
The following is an example of the diskusg command:
# /usr/sbin/acct/diskusg /dev/rrz3c 0 root 63652 1 daemon 84 2 bin 71144 4 adm 976 5 uucp 3324 322 homer 2 521 whistler 2 943 cellini 363 1016 pollock 92 1098 hopper 317
You must specify the raw device special file for filesystem (for example, /dev/rrz3c). A file system must exist on the target device.
The acctdusg command performs more thorough disk accounting than the diskusg command. If dodisk is invoked with the -o option, the acctdusg command is used to create the /var/adm/dtmp file.
The acctdusg command has the following syntax:
acctdusg[-u filename] [-p filename]
Refer to the acctdusg
(8) reference page for information on the command
options.
You must direct a binary disk usage file, usually /var/adm/dtmp, to the command. If the dodisk shell script invokes the command, the acctdusg command uses the file systems specified with the dodisk script as input.
The input to the acctdusg command is usually a list of files piped from a find / -print command. The command compares the file pathnames to the users' login directories ($HOME). If a file pathname is the same as a user's login directory, that user is charged for the file. Therefore, the directory in which the file is located is the determining factor in charging users for disk space. You can use the -u option to display the number of disk blocks used by files in directories other than the login directories.
For each file, the acctdusg command calculates the computed value, which is the number of disk blocks (including hidden or indirect blocks) that are allocated to the file divided by the number of hard links. If two or more users have links to the same file, the acctdusg command charges each user an equal percentage of the file's total disk space.
The acctdusg command output displays the user identification number, the user name, and the sum of the computed values of all the files owned by the user in three columns and adds leading 0s (zeros) to the user identification number. The acctdusg command does not display the disk-block count for empty directories.
The disk usage accounting records produced by the acctdisk command are usually merged with other accounting records to produce a total accounting report.
The chargefee shell script allows you to charge users according to the work performed. You should determine how much you want to charge for each service. Services can have different charge rates according to the time it takes to perform the task.
The chargefee shell script has the following syntax:
/usr/sbin/acct/chargefeeuser_name units
You can subtract units by specifying a dash (-) with the units variable.
The following example charges 7 units to user josh:
# chargefee josh 7
If the previous command is issued, the following record is written to the /var/adm/fee file:
1114 josh 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0
The printer accounting records enable you to charge users for the system printing resources and to track printer usage.
The two printer accounting files are located in either the /var/adm or the /var/adm/printer directory. The printer.acct printer user file lists the amount and cost of print media used, according to machine and user name. The printer.acct_sum printer summary file lists a summary of media produced according to machine and user name. The printer variable specifies the printer name. Refer to Chapter 11 for information on creating the printer accounting files.
Use the pac command to create a report of your printer activity. The pac command can obtain information only for printers that have accounting enabled. The pac command has the following syntax:
pac[-cmrs] [-pprice] [-Pprinter] [user . . .]
Refer to the pac
(8) reference page for information on the command
options.
Command | Description |
---|---|
runacct | This shell script creates the daily and summary files in the /var/adm/acct/nite and /var/adm/acct/sum directories. |
acctmerg | This command merges total accounting record files and allows you to combine process connect time, fee, disk usage, and print queue accounting records into files whose format you specify. The output can be in either the default binary format or ASCII format and can include up to 18 columns of accounting information. |
prtacct | This shell script formats and displays accounting files that have the /usr/include/sys/acct.h header file structure. Each record includes information about the user identification number, connect time, process time, disk usage, and printer usage. |
prdaily | This shell script creates an ASCII file that contains the accounting data from the previous day. When this script is invoked from the runacct script, it creates the /var/adm/acct/sum/rprtmmdd file. |
monacct | This shell script creates cumulative process and total accounting files in the /var/adm/acct/fiscal directory. |
The following sections describe the shell scripts and the command in detail.
The /var/adm/acct/nite directory contains files that are reused daily by the runacct script. Some of these files have binary counterparts in the /var/adm/acct/sum directory, which contains the cumulative summary files that are updated by the runacct shell script and used by the monacct shell script to produce monthly reports.
You can set up the cron daemon to invoke the runacct shell script each day, or you can invoke the runacct shell script manually. You may have to invoke the command manually if the runacct shell script does not complete or if a file created by the script becomes corrupted or lost.
When you invoke the runacct shell script it creates the /var/adm/acct/nite/lock temporary file. If the /var/adm/acct/nite/lock file exists, the runacct shell script will not run. Note
The runacct shell script executes in the following 13 states, in the order listed, and can be restarted at any of the 13 states:
State | Description |
---|---|
SETUP | Sets up some of the accounting files. |
WTMPFIX | Fixes corrupted date and time stamp entries that can cause commands such as the acctcon1 command to fail. |
CONNECT1 | Writes connect session records. |
CONNECT2 | Uses the connect session records to create a binary total accounting record that will be merged with other records to create a daily report. |
PROCESS | Produces process accounting report files. |
MERGE | Uses the acctmerg command to create the binary total accounting file. |
FEES | Uses the acctmerg command to merge records from the /var/adm/fee file into the binary total accounting file. |
DISK | Uses the acctmerg command to merge disk-usage records into the binary total accounting file. |
QUEUEACCT | Uses the acctmerg command to merge print queue accounting records into the binary total accounting file. |
MERGEACCT | Copies the binary total accounting file to the daily total accounting file, which is used as input to the acctmerg command to create the cumulative total daily accounting file. |
CMS | Produces command usage summaries. |
USEREXIT | Invokes any site-specific shell scripts. |
CLEANUP | Removes the temporary files. |
Fri Feb 4 11:02:56 EST 1994 -rw-r--r-- 1 adm adm 0 Jan 31 03:00 /var/adm/acct/nite/dacct -rw-rw-r-- 1 root system 924 Jan 05 10:45 /var/adm/wtmp -rw-rw-r-- 1 adm adm 0 Jan 08 13:46 fee -rw-rw-r-- 1 adm adm 0 Jan 07 02:00 pacct -rw-rw-r-- 1 adm adm 8904 Jan 02 11:02 pacct1 files setups complete wtmp processing complete connect acctg complete process acctg complete for /var/adm/Spacct1.1101 process acctg complete for /var/adm/Spacct2.1101 all process acctg complete for 1101 tacct merge to create daytacct complete no fees no disk records no queueing system records updated sum/tacct command summaries complete system accounting completed at Fri
If the runacct shell script fails or terminates before it is completed, you must restart the script from its last successfully completed state. The /var/adm/acct/nite/statefile file contains the name of the state that was last executed.
The runacct shell script has the following syntax:
/usr/sbin/acct/runacct[mmdd] [state]
The mmdd variable specifies the date for which you want to run the runacct shell script. Use the state variable to specify the state from which you want the runacct script to start processing.
If the runacct shell script fails on more than one successive day, invoke the SETUP state commands manually.
Before you restart the runacct shell script, you should remove the /var/adm/acct/nite/lock file and the /var/adm/acct/nite/lastdate file. Note
In the following example, the runacct shell script is invoked at its MERGE state and uses the accounting database files from January 26:
# runacct 0126 MERGE > /var/adm/nite/fd2log&
The following example invokes the runacct shell script, which uses the accounting database files from January 26 and specifies the nohup command so that signals, hangups, logouts, and quits are disregarded; any error messages generated during its execution are written to the fd2log file:
# nohup runacct 0126 > /var/adm/acct/nite/fd2log&
The default command output is in binary format, but you can also produce ASCII output. The default acctmerg command output has the /usr/include/sys/acct.h header file structure and includes up to 18 columns of accounting information. Records with the /usr/include/sys/acct.h header file structure that include data types specified as an array of two double elements can have both prime time and nonprime time values.
The runacct shell script invokes the acctmerg command. You can also invoke the command manually to produce reports. The acctmerg command has the following syntax:
/usr/sbin/acct/acctmerg[-ahiptuv] [#] [ file . . .]
Refer to the acctmerg
(8) reference page for information on command options.
# acctmerg -i1-2, 13, 18 < nite/dacct | sum/tacct
You can use the acctmerg command to correct errors in the /var/adm/sum/tacct file. Errors that can occur in the file include negative numbers and duplicate user identification numbers.
To correct errors in the current /var/adm/sum/tacct file:
# acctmerg -v < tacct.0617 > tacct_temp
# acctmerg -i < tacct_temp > tacct.0617
# acctmerg tacctprev < tacct.0617 > tacct
The monacct and prdaily shell scripts invoke the prtacct shell script. The runacct shell script invokes the prdaily shell script during its CLEANUP state. The prtacct shell script has the following syntax:
/usr/sbin/acct/prtacct[-f column] [-v] file
Refer to the prtacct
(8) reference page for information on the command
options.
The prdaily script combines information from the following six accounting files:
The prdaily shell script has the following syntax:
prdaily[-l[ mmdd]] | [-c]
Refer to prdaily
(8) for more information on command options.
Usually, you run the monacct script once each month to produce monthly report files. You can set up your cron daemon to run the shell script automatically. Refer to Section 13.2.4 for more information. The monacct shell script has the following syntax:
/usr/sbin/acct/monacct[number]
The number variable specifies an integer that is within the range 1 to 12 and that specifies the month for which you want to create the summary report. The default is the current month.
The monacct shell script creates the following files in the /var/adm/acct/fiscal directory: