made "hide files" and "veto files" into per-service parameter sections,
[Samba.git] / examples / printer-accounting / hp5-redir
blob98c2b72edd2249be2c1a7b03d1b4840354f520b4
1 #!/usr/bin/perl
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
13 umask(002);
15 # -w132 -l66 -i0 -n pkelly -h master.fcp.oypi.com /var/log/lp-acct
16 require "getopts.pl";
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)
23 = stat(STDIN);
25 # send to the real printer now.
26 open(P, "|lpr -Pmgmt0") || die "Can't print to hp5-real ($!)\n";
27 $cnt = 0;
28 while (sysread(STDIN, $buf, 10240)) {
29 print P $buf;
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);
34 close(P);
36 $acct = shift;
37 if (open(ACCT, ">>$acct")) {
38 print ACCT "$date $opt_n $opt_h $size $cnt\n";
39 close(ACCT);
40 } else {
41 warn "Err: Can't account for it ($!)\n";
42 warn "Log: $date $opt_n $opt_h $size $cnt\n";