Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Sep 2002 19:10:35 -0400
From:      Garance A Drosihn <drosih@rpi.edu>
To:        Warren Block <wblock@wonkity.com>, Roman Neuhauser <neuhauser@bellavista.cz>
Cc:        FreeBSD-Questions@FreeBSD.ORG
Subject:   Re: lpr Job Name
Message-ID:  <p05111704b9a813517d8c@[128.113.24.47]>
In-Reply-To: <Pine.BSF.4.21.0209130649450.49045-100000@wonkity.com>
References:  <Pine.BSF.4.21.0209130649450.49045-100000@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05111704b9a813517d8c>