Cups Filter for 2up or 4 up

Kurt Pfeifle kurt.pfeifle at infotec.com
Mon Aug 18 01:28:55 PDT 2008


> Hello List,
>
> I am running a cups server, which serves 2 floor of a Department with the required printers and some people like to have special features autoenabled by the printer.
>
> * 2up or 4up
>
> Of course, I could put this option in the lpoption file, however the server didn't send this option. This could be overridden, if I place an lpoption on each server, however this is overridden for instance by firefox automatically.
>
> I thought it would be the best to make an Bash-Filter (Code attached), which would do this work for me. The current problem is that the filter works perfectly if the is executed in the bash environment and it works sometime if it is executed by cups and sometime not !!
>
> #### Filter
>
> #!/bin/bash
>
> # 29.07.2008
>
> # CUPS filter to process 2-up using
> # Filter is User and Printer specified
> # Create a sandbox for working if input on stdin
>
> #
> # job id, user, job title, number of copies, and job options.
>
> if [ $# -lt 6  ]; then
>     cat - > "/tmp/$2-`date +'%H:%M:%S'`"
> else
>     cat $6 > "/tmp/$2-`date +'%H:%M:%S'`"
> fi
>
> FN="$2-`date +'%H:%M:%S'`"
> cd /tmp
>
> if [ "$2" != "" ]; then
>     cat "/tmp/$FN" | /usr/bin/psnup -n 2 > "/tmp/$FN-FIN"
>     cat "/tmp/$FN-FIN"
> else
>     cat "/tmp/$FN"
>     fi
>
> rm -f "/tmp/$FN" "/tmp/$FN-FIN"


One thing that immediately strikes me is that you use `date +'%H:%M:%S'` repeatedly inline in your code, to set a variable name.

This poses the danger, that you will get different values for this variable in case your script runs slowly (for whatever reason); in (rare) cases (even if your script runs fast), you'll see that one variable evaluation is taking place just before the $SECONDS value flips, and the next evaluation happens after the flip.

Your script will be more robust if you set "nowdate=`date +'%H:%M:%S'`" once and for all at the beginning of your script, and re-call it at all later occasions as ${nowdate}...

Not sure if *that* has caused your problem, but surely it *can* cause similar problems as your described one...





More information about the cups mailing list