1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 3<html> 4 <head> 5 <meta name="generator" content="HTML Tidy, see www.w3.org"> 6 <title>LPRng accounting.pl Utility</title> 7 <meta name="GENERATOR" content= 8 "Modular DocBook HTML Stylesheet Version 1.7"> 9 <link rel="HOME" title=" LPRng Reference Manual" href= 10 "index.htm"> 11 <link rel="UP" title="Accounting " href="accountingref.htm"> 12 <link rel="PREVIOUS" title="Reliable Accounting" href= 13 "x9772.htm"> 14 <link rel="NEXT" title= 15 "RFC 1179 - Line Printer Daemon Protocol " href= 16 "rfc1179ref.htm"> 17 </head> 18 19 <body class="SECT1" bgcolor="#FFFFFF" text="#000000" link= 20 "#0000FF" vlink="#840084" alink="#0000FF"> 21 <div class="NAVHEADER"> 22 <table summary="Header navigation table" width="100%" border= 23 "0" cellpadding="0" cellspacing="0"> 24 <tr> 25 <th colspan="3" align="center">LPRng Reference Manual: 5 26 Sep 2003 (For LPRng-3.8.22)</th> 27 </tr> 28 29 <tr> 30 <td width="10%" align="left" valign="bottom"><a href= 31 "x9772.htm" accesskey="P">Prev</a></td> 32 33 <td width="80%" align="center" valign="bottom">Chapter 34 18. Accounting</td> 35 36 <td width="10%" align="right" valign="bottom"><a href= 37 "rfc1179ref.htm" accesskey="N">Next</a></td> 38 </tr> 39 </table> 40 <hr align="LEFT" width="100%"> 41 </div> 42 43 <div class="SECT1"> 44 <h1 class="SECT1"><a name="AEN9787">18.7. <b class= 45 "APPLICATION">LPRng</b> accounting.pl Utility</a></h1> 46 47 <p>The <b class="APPLICATION">LPRng</b> <tt class= 48 "FILENAME">accounting.pl</tt> utility provides the basic 49 framework for using the <var class="LITERAL">:as=|</var>, 50 <var class="LITERAL">:ae=|</var>, and pagecounter information 51 written to the accounting file to do reliable accounting, and 52 may be found in the <b class="APPLICATION">LPRng</b> 53 distribution <var class="LITERAL">UTILS</var> directory. 54 Usually this is modified according to local site needs and 55 installed in the filter directory.</p> 56 57 <p>The utility maintains the accounting file by inserting a 58 <var class="LITERAL">START</var> record at the start of a job 59 and an <var class="LITERAL">END</var> record at the end of 60 the job. It is assumed that the last <var class= 61 "LITERAL">END</var> record in the file marks the last place 62 that accounting was completed.</p> 63 64 <p>The following shows the printcap entry for using the <var 65 class="LITERAL">accounting.pl</var> utility. The <var class= 66 "LITERAL">start</var> and <var class="LITERAL">end</var> 67 options are used to specify that the utility is being called 68 at the job start or end.</p> 69 70 <div class="INFORMALEXAMPLE"> 71 <a name="AEN9805"></a> 72<pre class="SCREEN"> 73 printer 74 :af=acct 75 :as=|/usr/local/libexec/filters/accounting.pl start 76 :ae=|/usr/local/libexec/filters/accounting.pl end 77</pre> 78 </div> 79 <br> 80 <br> 81 82 <p>At the start of each job the utilty writes a <var class= 83 "LITERAL">START</var> record into the accounting file. This 84 record can contain information suitable for use by local 85 site. The exit code and information written to the utility 86 <acronym class="ACRONYM">STDOUT</acronym> is used by the <var 87 class="LITERAL">lpd</var> server to determine if the job is 88 to be printed. This allows job quotas to be implemented in a 89 simple way by having the <var class= 90 "LITERAL">accounting.pl</var> utility query a database with 91 the user quotas and reject the job if the user's quota is 92 exceeded.</p> 93 94 <p>At the end of the job, the utilitity will read the 95 accounting file and use the recorded information to update 96 the accounting information. In order to make this reliable, 97 the following steps are taken.</p> 98 99 <ol type="1"> 100 <li> 101 <p>The accounting file is read and scanned for the last 102 <var class="LITERAL">END</var> record. If there is none, 103 then the next step starts at the beginning of the 104 accounting file.</p> 105 </li> 106 107 <li> 108 <p>The file is scanned for <var class= 109 "LITERAL">START</var> lines and <var class= 110 "LITERAL">pagecounter</var> information determined at the 111 start of a job.</p> 112 </li> 113 114 <li> 115 <p>If the last line in the accounting file does not 116 indicate successful completetion of the job and contain 117 pagecounting information, then the accounting procedure 118 is abandoned until the next job completes 119 successfully.</p> 120 </li> 121 122 <li> 123 <p>If the last line in the accounting file indicates 124 successful completion, then its pagecounter value is used 125 as the last page counter value.</p> 126 </li> 127 128 <li> 129 <p>Job information is updated by finding the start and 130 end pagecounter values for each job. It is possible that 131 a job will not have a pagecounter value recorded at its 132 start; in this case the page usage will be 0, as it did 133 not even get initialized.</p> 134 </li> 135 136 <li> 137 <p>After determining the accounting information, the 138 procedure will then update and databases and the 139 accounting file. During this update, interrupts should be 140 disabled and the amount of time taken to update the 141 accounting information and/or file should be 142 minimized.</p> 143 </li> 144 </ol> 145 <br> 146 <br> 147 148 <p>Administrators can use this script as a starting point for 149 more advanced accounting. For example, rather than just 150 recording the information, at the job start the script can 151 query either a local database or a remote server to see if 152 the user has permissions to access the printer. At the end of 153 the job or when an <acronym class="ACRONYM">END</acronym> 154 line is written to the accounting file, the local database or 155 remote accounting server can be updated.</p> 156 </div> 157 158 <div class="NAVFOOTER"> 159 <hr align="LEFT" width="100%"> 160 161 <table summary="Footer navigation table" width="100%" border= 162 "0" cellpadding="0" cellspacing="0"> 163 <tr> 164 <td width="33%" align="left" valign="top"><a href= 165 "x9772.htm" accesskey="P">Prev</a></td> 166 167 <td width="34%" align="center" valign="top"><a href= 168 "index.htm" accesskey="H">Home</a></td> 169 170 <td width="33%" align="right" valign="top"><a href= 171 "rfc1179ref.htm" accesskey="N">Next</a></td> 172 </tr> 173 174 <tr> 175 <td width="33%" align="left" valign="top">Reliable 176 Accounting</td> 177 178 <td width="34%" align="center" valign="top"><a href= 179 "accountingref.htm" accesskey="U">Up</a></td> 180 181 <td width="33%" align="right" valign="top">RFC 1179 - 182 Line Printer Daemon Protocol</td> 183 </tr> 184 </table> 185 </div> 186 </body> 187</html> 188 189