| Last change
 on this file since 462 was             1, checked in by Paul Smedley, 19 years ago | 
        
          | 
Initial code import
 | 
        
          | File size:
            998 bytes | 
      
      
| Line |  | 
|---|
| 1 | #!/usr/bin/perl | 
|---|
| 2 | # | 
|---|
| 3 | # 0 == stdin  == docuement | 
|---|
| 4 | # 1 == stdout == printer | 
|---|
| 5 | # 2 == stderr == logging | 
|---|
| 6 | # | 
|---|
| 7 | # With redirection to another valid /etc/printcap entry | 
|---|
| 8 | # | 
|---|
| 9 |  | 
|---|
| 10 | umask(002); | 
|---|
| 11 |  | 
|---|
| 12 | # -w132 -l66 -i0 -n pkelly -h master.fcp.oypi.com /var/log/lp-acct | 
|---|
| 13 | require "getopts.pl"; | 
|---|
| 14 | &Getopts("w:l:i:n:h:"); | 
|---|
| 15 |  | 
|---|
| 16 | chomp($date = `date '+%Y-%m-%d.%T'`); | 
|---|
| 17 |  | 
|---|
| 18 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | 
|---|
| 19 | $atime,$mtime,$ctime,$blksize,$blocks) | 
|---|
| 20 | = stat(STDIN); | 
|---|
| 21 |  | 
|---|
| 22 | # send to the real printer now. | 
|---|
| 23 | open(P, "|lpr -Pmgmt0") || die "Can't print to hp5-real ($!)\n"; | 
|---|
| 24 | $cnt = 0; | 
|---|
| 25 | while (sysread(STDIN, $buf, 10240)) { | 
|---|
| 26 | print P $buf; | 
|---|
| 27 | # this is ugly, but it gives the approx in pages.  We | 
|---|
| 28 | # don't print graphics, so ...  There must be a better way :) | 
|---|
| 29 | $cnt += ($buf =~ /^L/g); | 
|---|
| 30 | } | 
|---|
| 31 | close(P); | 
|---|
| 32 |  | 
|---|
| 33 | $acct = shift; | 
|---|
| 34 | if (open(ACCT, ">>$acct")) { | 
|---|
| 35 | print ACCT "$date $opt_n $opt_h $size $cnt\n"; | 
|---|
| 36 | close(ACCT); | 
|---|
| 37 | } else { | 
|---|
| 38 | warn "Err: Can't account for it ($!)\n"; | 
|---|
| 39 | warn "Log: $date $opt_n $opt_h $size $cnt\n"; | 
|---|
| 40 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.