From owner-freebsd-questions Fri Sep 13 16:10:51 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2C4F537B400 for ; Fri, 13 Sep 2002 16:10:44 -0700 (PDT) Received: from mail.rpi.edu (mail.rpi.edu [128.113.22.40]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5914743E65 for ; Fri, 13 Sep 2002 16:10:43 -0700 (PDT) (envelope-from drosih@rpi.edu) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by mail.rpi.edu (8.12.1/8.12.1) with ESMTP id g8DNAaAL330838; Fri, 13 Sep 2002 19:10:36 -0400 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: References: Date: Fri, 13 Sep 2002 19:10:35 -0400 To: Warren Block , Roman Neuhauser From: Garance A Drosihn Subject: Re: lpr Job Name Cc: FreeBSD-Questions@FreeBSD.ORG Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Scanned-By: MIMEDefang 2.3 (www dot roaringpenguin dot com slash mimedefang) Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG At 6:57 AM -0600 9/13/02, Warren Block wrote: >On Fri, 13 Sep 2002, Roman Neuhauser wrote: > > actually, that snippet is a UUCA nominee because the cat there > > is completely useless. someprog > /tmp/$USER/NameIWant would > > work just as well. > >Actually, it isn't. It took me a bit to see what Garance was talking >about. ">" isn't a command; you can't start a script with it, so you >need the cat to provide something to redirect: > > #!/bin/sh > # redirect stdin to a named file > cat > /tmp/$USER/NameIWant > # print and remove named file with lpr > lpr -r -Pblah /tmp/$USER/NameIWant > >Output can then just be piped to it. Exactly. Thanks. It would have been much less confusing if I had written it out as a script, instead of writing a few lines of code "which could be turned into a script". But I was pretty tired at the time, and I did not trust my ability to write a fully-wonderful script. Obviously it is much better to just fix lpr, but now that I'm much more awake I'll write something closer to a real working script: - - - - - - - - [start] #!/bin/sh # Example of a script which would implement 'lpr -Nsomename' # This is only an academic exercise, as it would be much better to # fix lpr itself to recognize -N (or something similar). # # NOTE: This has not actually been tested! # It is only an example! # ** USE AT YOUR OWN RISK! ** # # Garance/Sep 13/2002 NAME= COPT= JOPT= PTR= STDOPT= HAVEFILES= OPTERR= while test $# != 0 do case "$1" in -N*) NAME="`echo $1 | sed 's;^-N;;'`" ;; -C*) COPT="$1" ;; -J*) JOPT="$1" ;; -h|-m|-l) STDOPT="$STDOPT $1" ;; -P) PTR="-P$2" ; shift ;; -P*) PTR="$1" ;; -*) echo "Bad parameter to $PGM: $1" 1>&2 OPTERR=yes;; *) HAVEFILES=yes ; break ;; esac shift done if [ "$OPTERR" ] ; then exit 4 fi TDIR=/tmp/lpr-$USER-$$ if [ ! -d $TDIR ] ; then mkdir $TDIR ; chmod 700 $TDIR ; fi if [ -z "$NAME" ] ; then # No need to bother with temporary files lpr $PTR $STDOPT "$COPT" "$JOPT" "$@" exit $? fi if [ -z "$HAVEFILES" ] ; then # Read from stdin, write to temp file, then lpr the temp file. if [ -f "$TDIR/$NAME" ] ; then rm -Rf "$TDIR/$NAME" ; fi cat > "$TDIR/$NAME" lpr -r $PTR $STDOPT "$COPT" "$JOPT" "$NAME" exit $? else # Have to create a loop here, and process the file(s) one-at-a-time, # either adding a number to each $NAME, or doing a separate 'lpr' # for each file (in case the user specified multiple files). : fi - - - - - - - - [end] The above is made up of bits and pieces of other scripts that I have written. While I do not bet it will work, I do bet that it is much better than anything I would have come up with last night! -- Garance Alistair Drosehn = gad@gilead.netel.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message