<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta name="generator" content="HTML Tidy, see www.w3.org">
    <title>LPRng accounting.pl Utility</title>
    <meta name="GENERATOR" content=
    "Modular DocBook HTML Stylesheet Version 1.7">
    <link rel="HOME" title=" LPRng Reference Manual" href=
    "index.htm">
    <link rel="UP" title="Accounting " href="accountingref.htm">
    <link rel="PREVIOUS" title="Reliable Accounting" href=
    "x9871.htm">
    <link rel="NEXT" title=
    "RFC 1179 - Line Printer Daemon Protocol " href=
    "rfc1179ref.htm">
  </head>

  <body class="SECT1" bgcolor="#FFFFFF" text="#000000" link=
  "#0000FF" vlink="#840084" alink="#0000FF">
    <div class="NAVHEADER">
      <table summary="Header navigation table" width="100%" border=
      "0" cellpadding="0" cellspacing="0">
        <tr>
          <th colspan="3" align="center">LPRng Reference Manual: 24
          Sep 2004 (For LPRng-3.8.28)</th>
        </tr>

        <tr>
          <td width="10%" align="left" valign="bottom"><a href=
          "x9871.htm" accesskey="P">Prev</a></td>

          <td width="80%" align="center" valign="bottom">Chapter
          18. Accounting</td>

          <td width="10%" align="right" valign="bottom"><a href=
          "rfc1179ref.htm" accesskey="N">Next</a></td>
        </tr>
      </table>
      <hr align="LEFT" width="100%">
    </div>

    <div class="SECT1">
      <h1 class="SECT1"><a name="AEN9886">18.7. <b class=
      "APPLICATION">LPRng</b> accounting.pl Utility</a></h1>

      <p>The <b class="APPLICATION">LPRng</b> <tt class=
      "FILENAME">accounting.pl</tt> utility provides the basic
      framework for using the <var class="LITERAL">:as=|</var>,
      <var class="LITERAL">:ae=|</var>, and pagecounter information
      written to the accounting file to do reliable accounting, and
      may be found in the <b class="APPLICATION">LPRng</b>
      distribution <var class="LITERAL">UTILS</var> directory.
      Usually this is modified according to local site needs and
      installed in the filter directory.</p>

      <p>The utility maintains the accounting file by inserting a
      <var class="LITERAL">START</var> record at the start of a job
      and an <var class="LITERAL">END</var> record at the end of
      the job. It is assumed that the last <var class=
      "LITERAL">END</var> record in the file marks the last place
      that accounting was completed.</p>

      <p>The following shows the printcap entry for using the <var
      class="LITERAL">accounting.pl</var> utility. The <var class=
      "LITERAL">start</var> and <var class="LITERAL">end</var>
      options are used to specify that the utility is being called
      at the job start or end.</p>

      <div class="INFORMALEXAMPLE">
        <a name="AEN9904"></a>
<pre class="SCREEN">
    printer
     :af=acct
     :as=|/usr/local/libexec/filters/accounting.pl start
     :ae=|/usr/local/libexec/filters/accounting.pl end
</pre>
      </div>
      <br>
      <br>

      <p>At the start of each job the utilty writes a <var class=
      "LITERAL">START</var> 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
      <acronym class="ACRONYM">STDOUT</acronym> is used by the <var
      class="LITERAL">lpd</var> server to determine if the job is
      to be printed. This allows job quotas to be implemented in a
      simple way by having the <var class=
      "LITERAL">accounting.pl</var> utility query a database with
      the user quotas and reject the job if the user's quota is
      exceeded.</p>

      <p>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.</p>

      <ol type="1">
        <li>
          <p>The accounting file is read and scanned for the last
          <var class="LITERAL">END</var> record. If there is none,
          then the next step starts at the beginning of the
          accounting file.</p>
        </li>

        <li>
          <p>The file is scanned for <var class=
          "LITERAL">START</var> lines and <var class=
          "LITERAL">pagecounter</var> information determined at the
          start of a job.</p>
        </li>

        <li>
          <p>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.</p>
        </li>

        <li>
          <p>If the last line in the accounting file indicates
          successful completion, then its pagecounter value is used
          as the last page counter value.</p>
        </li>

        <li>
          <p>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.</p>
        </li>

        <li>
          <p>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.</p>
        </li>
      </ol>
      <br>
      <br>

      <p>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 <acronym class="ACRONYM">END</acronym>
      line is written to the accounting file, the local database or
      remote accounting server can be updated.</p>
    </div>

    <div class="NAVFOOTER">
      <hr align="LEFT" width="100%">

      <table summary="Footer navigation table" width="100%" border=
      "0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="33%" align="left" valign="top"><a href=
          "x9871.htm" accesskey="P">Prev</a></td>

          <td width="34%" align="center" valign="top"><a href=
          "index.htm" accesskey="H">Home</a></td>

          <td width="33%" align="right" valign="top"><a href=
          "rfc1179ref.htm" accesskey="N">Next</a></td>
        </tr>

        <tr>
          <td width="33%" align="left" valign="top">Reliable
          Accounting</td>

          <td width="34%" align="center" valign="top"><a href=
          "accountingref.htm" accesskey="U">Up</a></td>

          <td width="33%" align="right" valign="top">RFC 1179 -
          Line Printer Daemon Protocol</td>
        </tr>
      </table>
    </div>
  </body>
</html>



syntax highlighted by Code2HTML, v. 0.9.1