| Michal Szymanski on Tue, 5 Mar 2002 12:13:15 +0100 (CET)(envelope-from owner-apsfilter-help@apsfilter.org) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| patch: software page accounting and apsfilter |
On Thu, Feb 28, 2002 at 10:22:03PM +0100, Michael Loßin wrote:
> On 28-Feb-02 Michal Szymanski wrote:
> > I wonder how easy (or how difficult :) would it be to implement software
> > page accounting into apsfilter setup.
>
> In short: it's not worth trying.
>
> [snipped]
>
> If you really manage to set up a working software accounting
> system (I haven't seen one yet), please report it here...
Below, I include a patch (based on Michael's hints) to apply to
"apsfilter" in order to get simple software page accounting for a
PostScript (!) printer. Surely it is not bullet-proof but seems to work
acceptably fine in an environment (like in my institute) where:
1. Most if not all printer jobs are Postscript. Most users probably even
not know that our PS printers accept also PCL jobs :-)) Accounting
works only for PS jobs.
2. The admin wants only to know approximate page counts for particular
users, so if accounting fails for some jobs, nothing wrong happens.
No actual fees are charged. If a student starts to abuse the printer,
he/she will be just warned not to do it anymore.
3. The probability of someone deliberately cheating the accounting
system (by sending raw or hacked PS jobs) is neglectable.
The modified apsfilter does not do anything unless
"../etc/apsfilter/QUEUE/apsfilterrc" file contains a line:
SOFTWARE_ACCT='yes'
If so, a line is added to printer's accounting file (between jobstart
and jobend entries):
jobacct USER HOST QUEUE NO_OF_PAGES DATE HOUR JOBNAME
e.g.:
jobacct popielsk fornax.astrouw.edu.pl lw 1 2002/03/05 11:19:45 temp.ps
It would be nice if it could be included in future releases of
apsfilter, eliminating the need for manual patching the new versions.
Enjoy,
Michal Szymanski.
PS. I can't see the way this patch could do any harm but, of course,
standard disclaimer applies :)
--
Michal Szymanski (msz@astrouw.edu.pl)
Warsaw University Observatory, Warszawa, POLAND
================== apsfilter software accounting patch ====================
--- apsfilter.orig Mon Mar 4 15:05:23 2002
+++ apsfilter Tue Mar 5 10:16:01 2002
@@ -267,6 +267,27 @@
}
#=============================================================================
+# do_software_acct
+#
+# extract acct info from $APS_TMPDIR/count file written by ps_postprocessing
+#=============================================================================
+
+do_software_acct()
+{
+ local cnt
+
+ if [ -z "$SOFTWARE_ACCT" ]; then
+ return
+ fi
+ cnt=`sed 's/.*Wrote \(.*\) page.*/\1/' "$APS_TMPDIR/count"`
+ if [ $cnt = 0 ]; then
+ cnt=1
+ fi
+ echo jobacct $USER $HOST $QUEUE $cnt `date "+%Y/%m/%d %T"` $JOB \
+ >> ${ACCT_FILE:-/dev/null}
+}
+
+#=============================================================================
# print_ar
#
# Print a summary of an AR archive.
@@ -1123,9 +1144,11 @@
if [ "$DUPLEX" ] && [ "$PRINTER" != PS -o -z "$HARDWARE_DUPLEX" ]; then
unset DUPLEX
print_ps_duplex
+ do_software_acct
return
elif [ "$PRINTER" = PS ]; then
ps_postprocessing | print_data
+ do_software_acct
return
fi
@@ -1153,6 +1176,7 @@
gs_cmd="$gs_cmd | '$POST_FILTER' $POST_FILTER_OPTS"
fi
ps_postprocessing | eval $gs_cmd | print_data
+ do_software_acct
}
print_ps_duplex()
@@ -1218,7 +1242,8 @@
else
eval ${PS_UTILS:+$PS_UTILS |} ${PS_BOOK:+psbook -q |} \
${PS_NUP:+psnup -q -$PS_NUP ${LANDSCAPE:+$PSNUP_ROTATE}|} \
- ps_set_duplex
+ ps_set_duplex \
+ ${SOFTWARE_ACCT:+| psselect 2> $APS_TMPDIR/count}
fi
}