Unix systems which use the BSD/lpd-style spooling subsystem also usually offer printing accounting via the pac utility. Printer accounting is enabled with the af field in its /etc/printcap entry. For example, this entry designates /var/adm/ps1_acct as the accounting file for this printer:
laser|postscript|ps1:\ :lp=/dev/lp:sd=/var/spool/ps1:if=/usr/local/sbin/filt:\ :mx#0:af=/var/adm/ps1_acct:pw#132:pl#66:pc#100:\ ...
For text printers, the pw and pl fields (page width and length, in characters and lines, respectively) are used to generate accounting data. For other printer types, a more sophisticated approach is required.
Under AIX, printing accounting is enabled by adding an acctfile keyword to the queue definition stanza in /etc/qconfig:
laser: device = dlas1,dlas2 header = group trailer = never acctfile = /var/adm/qacct ...
This line may be added with a text editor, by using the chque command, or by using SMIT, but in any case, the queue should be stopped first (for example, with enq -D) and then restarted after reconfiguration (see Chapter 13 for more information).
By default, pac displays total usage of the current printer (as designated in an environment variable or as the system default printer) for each user on each host over the lifetime of the printer's accounting files. The units are pages for printers and linear feet for plotters and similar raster devices. You can combine all the host-specific entries for each user by including -m, since you seldom care where print jobs were spooled from.
You can specify what price to charge per unit with -p (the default is two cents, cheap even for the mid-1970s), where a unit is one page or one foot of continuous output. In addition, on systems using the printcap file, the pc entry can be used for the same purpose (its units are .01 cents). Thus, the example printcap entry at the beginning of this section set a page charge of 10 cents.
For example, this command produces a report of printer usage for the listings printer (specified as usual with -P), with one entry per user and a charge of 12 cents per page:
# pac -m -p0.12 -Plistings Login pages/feet runs price chavez 132.00 50 USD 15.84 silk 114.00 9 USD 13.68 harvey 16.00 2 USD 1.92 ... total 5361.00 378 USD 643.32
A total line for all users appears at the bottom of the report. pac is quite picky about its syntax, requiring options to follow the option letter immediately and not allowing you to concatenate options behind a single minus sign.
You can limit the report to specific users by including one or more usernames at the end of the pac command line. pac's other report-related options are -c, which sorts output by cost rather than username, and -r, which reverses the sort ordering in either mode. It also has a -s option, which produces a summary file from the raw data file; the summary file has the name of the raw data file with _sum appended to it.
If you want date-based printer accounting reports, you'll have to generate them yourself. For example, the following script produces a printer-account report for the current week (it is designed to be run via the cron facility):
#!/bin/sh # pracct - run printing accounting report cd /var/adm while [ $# -gt 0 ]; do file="$1.`date +%m-%d-%y`" echo "Printing Usage Report for Printer $1" > $file echo "Covering the week ending `date +%m-%d-%y" >> $file /usr/sbin/pac -m -p0.12 -P$1 >> $file if [ -s $1_lastweek ]; then mv -f $1_lastweek $1_prevweek fi /usr/sbin/pac -s mv $1_sum $1_lastweek done
The script saves pac's output to a file named for the printer and the current date after writing two header lines to it. It then creates a (smaller) summary file from the current printer accounting file (assumed to be named the same as the printer), which it renames, so that its data will not appear in future pac output (if a file is present, summary file data is included). This script arranges to save the summary files for the past two weeks online by renaming last week's file (if it exists) before creating the current week's summary file.
17.4.1 Printer Accounting Under LPRng
LPRng uses the same field for specifying the accounting file as the LPD system: af. In addition, it provides some additional flags:
Typical accounting records from the example program look something like this:
start -p100 -Fo -kjob . . . Start of print request (-Fo); counter is 100. start -p100 -Ff -kjob . . . Start of first component file (-Ff). end -p10 -q 110 -Ff -kjob . . . End of first file (10 pages). start -p110 -Ff -kjob . . . Start of second component file. end -p5 -q115 -Ff -kjob . . . End of second job (5 pages). end -p115 -Fo -kjob . . . End of print request; counter is 115.
Each line displays the current print counter setting (-p in start lines and -q in end lines), and a flag indicating whether the entry applies to a print request or an actual printed file, and other information about the job (the job ID, submitting user and host, and the like).
See the LPRng documentation for full details on its printer accounting capabilities.