Whole document tree
    

Whole document tree

\LPRng accounting.pl Utility

18.7. \LPRng accounting.pl Utility

The LPRng accounting.pl utility provides the basic framework for using the :as=|, :ae=|, and pagecounter information written to the accounting file to do reliable accounting, and may be found in the LPRng distribution UTILS directory. Usually this is modified according to local site needs and installed in the filter directory.

The utility maintains the accounting file by inserting a START record at the start of a job and an END record at the end of the job. It is assumed that the last END record in the file marks the last place that accounting was completed.

The following shows the printcap entry for using the accounting.pl utility. The start and end options are used to specify that the utility is being called at the job start or end.

    printer
     :af=acct
     :as=|/usr/local/libexec/filters/accounting.pl start
     :ae=|/usr/local/libexec/filters/accounting.pl end


At the start of each job the utilty writes a START record into the accounting file. This record can contain information suitable for use by local site. The exit code and information written to the utility STDOUT is used by the lpd server to determine if the job is to be printed. This allows job quotas to be implemented in a simple way by having the accounting.pl utility query a database with the user quotas and reject the job if the user's quota is exceeded.

At the end of the job, the utilitity will read the accounting file and use the recorded information to update the accounting information. In order to make this reliable, the following steps are taken.

  1. The accounting file is read and scanned for the last END record. If there is none, then the next step starts at the beginning of the accounting file.

  2. The file is scanned for START lines and pagecounter information determined at the start of a job.

  3. If the last line in the accounting file does not indicate successful completetion of the job and contain pagecounting information, then the accounting procedure is abandoned until the next job completes successfully.

  4. If the last line in the accounting file indicates successful completion, then its pagecounter value is used as the last page counter value.

  5. Job information is updated by finding the start and end pagecounter values for each job. It is possible that a job will not have a pagecounter value recorded at its start; in this case the page usage will be 0, as it did not even get initialized.

  6. After determining the accounting information, the procedure will then update and databases and the accounting file. During this update, interrupts should be disabled and the amount of time taken to update the accounting information and/or file should be minimized.



Administrators can use this script as a starting point for more advanced accounting. For example, rather than just recording the information, at the job start the script can query either a local database or a remote server to see if the user has permissions to access the printer. At the end of the job or when an END line is written to the accounting file, the local database or remote accounting server can be updated.