I asked:
> Date: Wed, 17 Jan 1996 14:59:29 -0500 (EST)
> From: Todd Pfaff <todd@water.eng.mcmaster.ca>
> To: sun-managers@eecs.nwu.edu
> Subject: Postscript page accounting in Solaris 2.x
> Followup-To: junk
>
> We have an HP LaserJet 4MP connected to a serial port of a SPARCstation
> running Solaris 2.5. We'd like to do page accounting for each print job.
> Under SunOS 4.1.x we were running the lprps/psif/textps programs to filter
> text and count pages. I've managed to get lprps running under Solaris
> 2.5 and I have it called as a filter from the /etc/lp/interfaces/printer
> script, but it's not working correctly.
>
> I'm getting these messages out of lprps:
>
> Jan 17 13:33:33 crocus lprps[16109]: hplj4mp is not responding
> Jan 17 13:40:33 crocus last message repeated 6 times
> Jan 17 13:41:33 crocus lprps[16109]: hplj4mp: couldn't make printer ready to receive job
>
> Before I try to debug this further, I'd like to know if anyone else is
> using lprps under Solaris 2.x and if so, can you send me any special
> instructions or source code modifications.
>
> Does anyone know of any other solutions for doing page accounting for this
> environment?
>
> --
> Todd Pfaff \ Email: pfaff@mcmaster.ca
> Computing and Information Services \ Voice: (905) 525-9140 x22920
> ABB 132 \ FAX: (905) 528-3773
> McMaster University \
> Hamilton, Ontario, Canada L8S 4M1 \
I've put together a solution that works with Solaris 2.4/2.5 and a
serially connected HP LaserJet 4MP printer. It should work with any
serially connected Postscript printer, but I don't know about parallel.
- set the HP LaserJet 4MP to Postscript mode from the front-panel
- apply the attached context diff to /usr/lib/lp/model/standard
- use admintool to add the printer and set the printer type to postscript
and set the content types to postscript
- alternatively, you can apply the context diff to an existing
/etc/lp/interfaces/printername script
- add an entry to syslog.conf to log local2.info messages to
/var/adm/pagecount
- copy pac from a SunOS 4.1.x system to /usr/local/bin/pac
- run the attached pac.sh frontend script to generate a report from the
pagecount log. pac.sh takes parameters to specify report mail
recipient, price-per-page, printer name, and whether to save and
truncate the log file.
Please note, this isn't bulletproof. I've only been running it for about
a month and I just noticed in my first monthly report that one of the
print jobs reported a negative page count (-2 pages) and pac reported this
as -2 pages printed by Login -2.0:
Login pages/feet runs price
-2.0 -2.00 1 $ -0.04
-- Todd Pfaff \ Email: pfaff@mcmaster.ca Computing and Information Services \ Voice: (905) 525-9140 x22920 ABB 132 \ FAX: (905) 528-3773 McMaster University \ Hamilton, Ontario, Canada L8S 4M1 \
*** standard+pagecount Tue Jun 4 14:50:34 1996
--- standard Wed Oct 25 07:30:48 1995
***************
*** 60,85 ****
# Set some globally used variables and functions.
#####
- # $2 is $host!$login
- login=`echo $2 | awk -F'!' '{print $2}'`
- fromhost=`echo $2 | awk -F'!' '{print $1}'`
-
- get_pagecount () {
- pc=""
- while [ "$pc" = "" ]
- do
- pc=`/usr/lib/lp/postscript/postio \
- -l /dev/ttya \
- -b 38400 \
- -P "(\012pagecount = ) print statusdict begin pagecount end 20 string cvs print (\012) print flush" \
- /dev/null \
- 2>&1 \
- | grep pagecount \
- | awk '$1 == "pagecount" {print $3; exit}'`
- done
- echo $pc
- }
-
: ${TMPDIR:=/tmp}
: ${SPOOLDIR:=/usr/spool/lp}
: ${TERMINFO:=/usr/lib/terminfo}
--- 60,65 ----
***************
*** 571,577 ****
#####
stty \
! 38400 \
0<&1 2>/dev/null 1>&2
stty \
cs8 -cstopb -parenb -parodd \
--- 551,557 ----
#####
stty \
! 9600 \
0<&1 2>/dev/null 1>&2
stty \
cs8 -cstopb -parenb -parodd \
***************
*** 982,989 ****
trap '' 1 # Let the filter handle a hangup
trap '' 2 3 # and interrupts
(
- pagecount1=`get_pagecount`
-
#####
# Put the 0<${file} before the "eval" to keep
# clever users from giving a file name that
--- 962,967 ----
***************
*** 991,1001 ****
#####
0<${file} eval ${FILTER} 2>&1 1>&3
echo $? >${EXIT_CODE}
-
- pagecount2=`get_pagecount`
- pc=`expr $pagecount2 - $pagecount1`
- logger -p local2.info $printer $fromhost $login $pc
-
) | ${LPTELL} ${LPTELL_OPTS} ${printer}
trap 'catch_hangup; exit_code=129 exit 129' 1
trap 'catch_interrupt; exit_code=129 exit 129' 2 3
--- 969,974 ----
#!/bin/sh
#
# - preprocess pagecount syslog file to create input file for pac program
# - run pac on the resulting output
# Note: Solaris 2.x doesn't have the pac program
# but the SunOS 4.1.x version works)
#
# Todd Pfaff
# pfaff@mcmaster.ca
# May 8, 1996
usage () {
echo "Usage: `basename $0` [-h] [-m mailto] [-p price] [-P printer] [-t]"
echo " -h show this help message"
echo " -m mailto mail report to this address"
echo " -p price price per page"
echo " -P printer process for this printer"
echo " -t save and truncate the pagecount log file"
}
bad_usage () {
usage
exit 1
}
aflog=/var/adm/pagecount
aflog2=$aflog.`date +'%y%m%d'`
af=/tmp/pagecount.$$
report=/tmp/pac-report.$$
printcap=/etc/printcap
printer=lp
price=0.05
while [ $# -gt 0 ]; do
case $1 in
"-h")
usage
exit 0
;;
"-m")
shift && [ $# -eq 0 ] && bad_usage
mailto=$1
;;
"-p")
shift && [ $# -eq 0 ] && bad_usage
price=$1
;;
"-P")
shift && [ $# -eq 0 ] && bad_usage
printer=$1
;;
"-t")
opt_t=1
;;
*)
bad_usage
esac
shift
done
if [ $opt_t ]; then
/bin/cp $aflog $aflog2
/bin/cp /dev/null $aflog
aflog=$aflog2
fi
cat $aflog | awk ' \
BEGIN { prev = "" } \
$7 == "repeated" && prev != "" { for (i = 0; i < $8; ++i) print prev } \
$6 == "'$printer'" { prev = sprintf "%s.0 %s:%s",$9,$7,$8; print prev } \
$6 != "'$printer'" { prev = "" } \
' > $af
exit
if [ -r $printcap ]; then
echo "page accounting failure: $printcap exists"
exit 1
fi
cat > $printcap << EOF
$printer:af=$af
EOF
subject="printer accounting report for printer $printer on host $HOST"
(
echo "$subject"
echo "`date`"
echo " "
/usr/local/bin/pac -P$printer -p$price
) > $report
if [ $mailto ]; then
mail -s "$subject" $mailto < $report
else
cat $report
fi
/bin/rm -f $printcap
/bin/rm -f $af
/bin/rm -f $report
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:00 CDT