Written by Urs-Jakob Rüetschi
as part of the pracc project.

Pracc Tools, v2

Command-line tools to work with Pracc.

All tools have a -V and a -h option; -V shows the tool's name and version, -h shows a short help message; both print to standard output and then exit successfully.

All tools use these exit codes: 0 for success, 111 for temporary errors, and 127 for permanent errors.

Tools that modify pracc files document their activity by appending a line to the pracc.log file.

pracc-init

Usage: pracc-init [-fF] account balance limit {info}

Create a pracc file for account with the given initial balance (zero or greater) and limit (any integer). A value of "none" (without the quotes) for limit means no limit. Optional info arguments are appended to the pracc file header line.

If -f is specified, re-create the pracc file even if it already exists.
If -F is specified, quit successfully if the pracc file already exists.
Otherwise just complain and leave the existing file alone.

Example of an initial pracc file with balance=500 and limit=9 for user wimmer (additional info: Waldemar Immerfroh):

#pracc-v2-0-wimmer Waldemar Immerfroh
$9 @4000000042cd8078 root minimum balance
=500 @4000000042cd8078 root initial credit

pracc-edit

Usage: pracc-edit account action arg {info}

Perform action on account. The action is one of debit, credit, reset, limit, note; it means to atomically append a line of that type to the pracc file. Depending on action, arg is an amount, a balance, or a limit. The special limit "none" (without the quotes) makes the account unlimited.

Must be root or in group pracc to use this tool. Do not install it set-gid pracc!

Usage examples and the corresponding lines that are appended:

# pracc-edit wimmer credit 500 new credits
+500 @4000000042d0691c root new credits
# pracc-edit wimmer debit 500 storno
-500 @4000000042d06951 root storno
# pracc-edit wimmer reset 500 new balance
=500 @4000000042d06a05 root new balance
# pracc-edit wimmer limit none account now unlimited
$* @4000000042d06a7b root account now unlimited
# pracc-edit wimmer limit -1000000 new limit
*-1000000 @4000000042d06ac3 root new limit
# pracc-edit wimmer note merry x-mas
# merry x-mas

Scripts like this one might be useful:

#!/bin/sh
USAGE="Usage: pracc-credit account amount {info}"
usage() { test "$*" && echo $*; usage $USAGE; exit 127; }
test -n "$1" && ACCOUNT="$1" || usage "missing account"
test -n "$2" && AMOUNT="$2" || usage "missing amount"
shift 2 && pracc-edit "$ACCOUNT" credit "$AMOUNT" $*

pracc-view

Usage: pracc-view [options] account

Print the given account to standard output. Errors in the pracc file are reported to standard error. Use one or more of the following options to view only records that match all of the restrictions specified:

-f date
only show records from (and including) date
-u date
only show records until (and including) date
-t type
only show records of the given type

Dates are in yyyy-mm-dd format, e.g., 2005-07-15.
Valid types are: debit, credit, reset, limit, note.
Use -t more than once to select several types.

pracc-kill

Usage: pracc-kill [-f] account [comment]

Delete the given account and note this fact, along with any comment arguments, to the common log file. Use -f to really delete the account, without this flag just pretend.

pracc-sum

Usage: pracc-sum [options] account

Summarise the given account by printing to standard output its balance B, limit L, sum of credits Sc, sum of debits Sd, and the date/time of the account's last use.

acct name balance B limit L credits Sc debits Sd last yyyy-mm-dd

Optionally, summarise only for a given time period; default is for the whole account.

-f date
Set start of period for summary: records older than date are only used for computing the account's balance and limit, but not for the credit and debit summary.
-u date
Set end of period for summary: records newer than date are ignored when summarising the account.

Dates are in yyyy-mm-dd format, e.g., 2005-07-15.

Return 0 if the balance is greater than the account's limit; otherwise exit with status 1. If there is an error, return 111 (temporary error) or 127 (permanent).

pracc-credit (TODO)

Usage: pracc-credit account < voucher-file

Add credits to the given account by reading a voucher file from stdin, checking its validity, appending a credit record to account, marking the voucher as used, and appending a record to the common log file.

  1. find voucher in pracc.ppc (list of pre-paid credits)
  2. append record to pracc.log (journaling)
  3. mark voucher as used in pracc.ppc
  4. append credit record to pracc file
  5. don't crash between steps 3 and 4...

pracc-purge (TODO)

Usage: pracc-purge [options] account date

Purge old records from the given account without changing its balance or limit. A record is old if it is older than date, which must be specified in yyyy-mm-dd format, e.g., 2005-07-15.

It might be useful to keep old records of some types:
Add -l to keep old limit records.
Add -r to keep old reset records.
Add -n to keep old note records.

The purge process works by scanning through the pracc file for account, skipping old records and copying non-old records to a temporary file PRACCDIR/account.purge. After skipping the last old record and before copying the first non-old record to the temporary file, a copy of the most recent limit record and a reset record with the current balance is written to the temporary file. This way, the account's balance and limit remain the same as they were in the original file. When done copying, the temporary file is moved over the original pracc file, which completes the purge process.

Add -D to only create the temporary file but not move it over the original pracc file. This is mainly useful for testing. Note that pracc-purge fails if the temporary file already exists, so remember to delete it yourself.

Note that comment lines do not have a timestamp. For purging, they inherit the timestamp of the most recent line before with a valid timestamp. Initial comment lines are never purged.

Lines longer than MAXLINE (see pracc.h) are truncated to that length.
Syntactically incorrect lines are silently removed.

This tool does not produce any output to stdout. Error messages go to stderr.

pracc-check

Usage: pracc-check [account]

Check the installation of the pracc system and report any problems found to standard output. What constitutes a correct installation depends on the pracc.h header file and is defined below.

If an optional account is specified, then this account file is checked for syntactical correctness and any errors found are reported to standard output.

PRACCDIR
the directory where all pracc files reside;
/var/print/pracc/ is default
PRACCBIN
the directory where all pracc tools reside;
/var/print/bin/ is default
PRACCLOG
the full path of the common log file;
/var/print/pracc.log is default
PRACCDEFLT
name of the default account;
default is default
PRACCOWNER
the owner used for pracc files;
root is default and fine
PRACCGROUP
the group used for pracc files;
lpadmin is default but a dedicated group is better
PRACCADMIN
used by the web interface only:
users of this group can perform administrative functions;
lpadmin is default, but a dedicated group is better
PRACCDOC
used by the web interface only:
directory that contains the templates, documents, etc.;
/var/print/doc/ is default
PRACCWEBUI
full path to the web interface CGI tool;
/var/print/cgi/pracc.cgi is default
TypeModeOwnerGroupResourceNotes
d2770 PRACCOWNERPRACCGROUP PRACCDIR/required
r660 PRACCOWNERPRACCGROUP PRACCDIR/PRACCDEFLTrequired
r660 PRACCOWNERPRACCGROUP PRACCDIR/accountoptional
r660 PRACCOWNERPRACCGROUP PRACCLOGrequired
dany anyany PRACCBIN/optional
r755 anyany PRACCBIN/tooloptional
r2755 PRACCOWNERPRACCGROUP PRACCBIN/pracc-creditoptional
d755 anyany PRACCDOC/required
dany anyany PRACCWEBUIrequired

pracc-log

Usage: pracc-log [options] [account]

Print entries from the common log file to standard output. If account is specified, print only entries pertinent to that account. Use options to restrict output to a certain range of dates. Malformed log lines are silently skipped.

-f date
only show entries from (and including) date
-u date
only show entries until (and including) date

Dates are in yyyy-mm-dd format, e.g., 2005-07-15.

pracc-pclog

Usage: pracc-pclog [options] [printer]

Read the pc.log file and write statistics per printer to standard output. If no printer argument is specified, look at all printers that have entries in pc.log.

-f date
only show entries from (and including) date
-u date
only show entries until (and including) date
printer
only look at printers matching printer (wildcards)

Dates are in yyyy-mm-dd format, e.g., 2005-07-15.

pracc-scan

Usage: pracc-scan [options] [file]

Scan a print job file for its page count and information like duplex printing, paper size, etc. Known job formats are: PJL, PCL5, PCLXL (aka PCL6), and PostScript. If file is not specified, read from standard input.

Historical note:

This is a wrapper around joblex, a "lexer" for print jobs, originally written in about 2007 and since extended to support PCL XL. Presently, it produces one line to standard output with this format (# stands for a number):

# pages=# sheets=# copies=# duplex=# color=# struct=foo

Example:

5 pages=5 sheets=3 copies=1 duplex=1 color=-1 struct=UJ6UJU

Joblex believes that this job prints 1 copy of a duplex job, resulting in 5 printed pages on 3 sheets of paper; joblex has no idea if this is a color or monochrome job (color=-1). The print job consists of a UEL (U), some PJL (J), PCL XL (6), followed by UEL @PJL UEL (UJU).

The first number is always the same as pages and for compatibility with cupspracc (which reads the first number of the first line of a job scanner's output).

Presently, color=1 represents @PJL PLANESINUSE = 3 (color) and color=0 represents @PJL SET PLANESINUSE = 1 (monochrome). It seems that many black-and-white jobs have @PJL SET PLANESINUSE = 3.

Log file

There is a common log file, where account modifications are recorded. By default, the log file is /var/print/pracc.log, but this can be changed at compile-time. Here is what the tools log:

v1, ujr/2003-11-13
v2, ujr/2005-06-18
latest: 2012-09-03