3 # $Source: /data/src/mirror/cvs/samba/examples/printer-accounting/hp5-redir,v $
4 # $Id: hp5-redir,v 1.1 1996/07/23 03:30:56 samba-bugs Exp $
6 # 0 == stdin == docuement
7 # 1 == stdout == printer
8 # 2 == stderr == logging
10 # With redirection to another valid /etc/printcap entry
15 # -w132 -l66 -i0 -n pkelly -h master.fcp.oypi.com /var/log/lp-acct
17 &Getopts
("w:l:i:n:h:");
19 chomp($date = `date '+%Y-%m-%d.%T'`);
21 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
22 $atime,$mtime,$ctime,$blksize,$blocks)
25 # send to the real printer now.
26 open(P
, "|lpr -Pmgmt0") || die "Can't print to hp5-real ($!)\n";
28 while (sysread(STDIN
, $buf, 10240)) {
30 # this is ugly, but it gives the approx in pages. We
31 # don't print graphics, so ... There must be a better way :)
32 $cnt += ($buf =~ /^L/g);
37 if (open(ACCT
, ">>$acct")) {
38 print ACCT
"$date $opt_n $opt_h $size $cnt\n";
41 warn "Err: Can't account for it ($!)\n";
42 warn "Log: $date $opt_n $opt_h $size $cnt\n";