[comp.sources.misc] v07i062: a remote printer script for System V

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (07/09/89)

Posting-number: Volume 7, Issue 62
Submitted-by: Paul Blackburn <mcvax!oasis.icl.stc.co.uk!mpb@uunet.UU.NET>
Archive-name: lp-remote

[I wonder how many times this particular wheel has been re-invented?  I've
done a few of these myself (one each for uucp and WIN/3B); however, it's
abotu time someone actually *posted* one.  ++bsa]

I enclose a remote printer script which I have written and found to be
very handy for sharing expensive printers.

It has been tested on System V but not BSD.
[Won't work under BSD:  they use a different spooler.  ++bsa]
-- 
Cheers,     "did Bostic really send the fix or was it his evil twin, Skippy?"
       Paul Blackburn, ICL, Lovelace Road, Bracknell, Berkshire, RG12 4SN, UK
mpb@oasis.icl.stc.co.uk  OR  ...!uunet!mcvax!ukc!iclbra!mpb
------------------------------------------cut here---------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	remotelp
# This archive created: Fri Jun 16 16:13:24 1989
export PATH; PATH=/bin:$PATH
if test ! -d 'remotelp'
then
	echo shar: creating directory "'remotelp'"
	mkdir 'remotelp'
fi
echo shar: entering directory "'remotelp'"
cd 'remotelp'
echo shar: extracting "'README'" '(2899 characters)'
if test -f 'README'
then
	echo shar: will not over-write existing file "'README'"
else
sed 's/^X//' << \SHAR_EOF > 'README'
XRemote printer script installation notes Sys V          mpb 22 Dec 88
X----------------------------------------------          -------------
X
XPre-amble:
X
XThis script was written to allow a set of small UNIX machines
Xto share two expensive laser printers.
X
XIt makes use of uux to transfer the file-to-be-printed to the
Xmachine that has the printer connected.
X
XIt is tried and tested on System V (both .2 and .3) but not
Xon BSD.
X
X1. Files required
X
X   /usr/spool/lp/model/remote
X   /usr/spool/lp/db
X
X2. Adding a new remote printer
X
X   a. Decide on name for new printer (for example, 'laser')
X   b. Make sure you have a working uucp link to the remote machine
X      and that the remote m/c uucp system will allow the 'lp' command
X      to be executed.
X   c. Become superuser
X   d. Shut down the lp scheduler and set up new printer thus:
X
X      cd /usr/lib
X      ./lpshut
X      ./lpadmin -plaser -mremote -v/dev/null
X      ./accept laser
X      enable laser
X      lpstat -t
X
X   e. Re-start the lp scheduler: ./lpsched
X
X   f. Edit the lp database file (/usr/spool/lp/db) to reflect your remote
X      printer configuration.
X
X   First, make sure there is a line beginning with the name of the printer:
X
Xlaser:pluto:CANON::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
X^^^^^
X
X   Second, make sure the second field is the name of the machine
X   to which your local machine has a uucp link.
X
Xlaser:epcfta:CANON::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
X      ^^^^^^
X
X   The third field is a comment field, use a name to describe the printer.
X
Xlaser:epcfta:CANON lbp8::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
X             ^^^^^^^^^^
X
X   The fourth field is for the name of the printer on the remote machine.
X   Normally this would be the same the local print model (i.e. laser).
X   If the remote computer has a different name for the printer you wish
X   to access then set the name here (blank means same name).
X
X   You can see what printers a machine has available by typing: lpstat -t
X
Xlaser:epcfta:CANON lbp8::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
X                       ^^
X
X   The fifth and sixth fields are optional. They specify escape sequences
X   for small and landscape printing on the remote printer. You will need
X   to refer to the printer manual to check these sequences are correct
X   for your remote printer.
X
X   To use these features you would type:
X
X       lp -dlaser -ol myfile        # for landscape
X
X       lp -dlaser -os myfile        # for small printing
X
X
XHave fun,
X
XPaul Blackburn        |  /~~~\          | Mail:    mpb@oasis.icl.stc.co.uk
XICL, Lovelace Road    | (\@,@/)         |   ...!uunet!mcvax!ukc!iclbra!mpb
XBracknell, Berkshire  |  \_=_/     .zZz |      Phone: +44 344 424842 x2648
XRG12 4SN, UK          |  / " \          |         Telex:    22971 STCICL G
X                      |'fly-by-wire' :-)|              Fax: +44 344 487832
SHAR_EOF
fi # end of overwriting check
echo shar: extracting "'db'" '(1273 characters)'
if test -f 'db'
then
	echo shar: will not over-write existing file "'db'"
else
sed 's/^X//' << \SHAR_EOF > 'db'
X# NAME		/usr/spool/lp/db
X# DATE		Thu Jul 14 13:32:12 BST 1988
X# AUTHOR	Paul Blackburn, DRSBC, ICL, Bracknell
X# PURPOSE	Database of 'remote' printers.
X#		This file is grep'ed by remote printer scripts to get
X#		details for a printer: The format is:
X#
X# <printer>:<next>:<description>:<remote>:<small>:<landscape>
X#
X# Where:
X# M	<printer>	= name of printer used in 'lp -d<printer>'.
X#			  This field is mandatory.
X#
X# M	<next>		= name of next machine to uux to.
X#			  This field is mandatory.
X#
X# O	<description>	= description of printer
X#			  This field is optional.
X#
X# O	<remote>	= name of printer of remote machine (usually
X#			  same as <printer>, defaults to same)
X#			  This field is optional.
X#
X# O	<small>		= printer command to switch to small print
X#			  This field is optional.
X#
X# O	<landscape>	= printer command to switch to L/S print
X#			  This field is optional.
X#
X# The commands for small and landscape are escape sequences and are
X# 'echo'ed to the printer.
X#
X# NB as ':' is used to delimit fields use '\072' in command sequences
X#laser:pluto:RICOH:lzr:"\033\022D3 \c:\033\022D4 \c:
X
Xlbp8:pluto:CANON::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
Xlaser:gator:RICOH:pookie:"\033\022D3 \c:\033\022D4 \c:
Xdevps:pebbles:PostScript::::
Xml193p:tigger:::::
SHAR_EOF
fi # end of overwriting check
echo shar: extracting "'remote'" '(2982 characters)'
if test -f 'remote'
then
	echo shar: will not over-write existing file "'remote'"
else
sed 's/^X//' << \SHAR_EOF > 'remote'
X# NAME		/usr/spool/lp/model/remote
X# DATE		Thu Jul 14 13:31:26 BST 1988
X# AUTHOR	Paul Blackburn, DRSBC, ICL, Bracknell
X# PURPOSE	This is a 'remote' spooler script for any printer.
X#		This works by sending a 'uux' print request to a neighboring
X#		machine (NEXT).
X#
X#		This is a 'data-driven' script...
X#		/usr/spool/lp/db is used to get data for a particular printer.
X#
X#		(local) Options:
X#
X#			-os	= small print (portrait)
X#			-ol	= small print (landscape)
X
XLOG=/usr/spool/lp/log
XDB=/usr/spool/lp/db
XMODEL=`basename $0`
XTEMP=/usr/tmp/${MODEL}.$$
X
Xif [ ! -f ${DB} ]
Xthen
X	echo "${MODEL}: unable to open ${DB}" >>$LOG
X	echo "${MODEL}: aborted" >>$LOG
X	exit 1
Xfi
X
Xgrep "^${MODEL}:" ${DB} >${TEMP}
X
XDATA=`cat ${TEMP}`
X
Xif [ -z "${DATA}" ]
Xthen
X	echo "${MODEL}: unable to get data from ${DB}" >>$LOG
X	echo "${MODEL}: aborted" >>$LOG
X	rm -f ${TEMP}
X	exit 1
Xfi
X
XNEXT=`cut -f2 -d":" <${TEMP}`
XDESC=`cut -f3 -d":" <${TEMP}`
XRMODEL=`cut -f4 -d":" <${TEMP}`
Xif [ -z "${RMODEL}" ]
Xthen
X	RMODEL=${MODEL}
Xfi
XSMALL=`cut -f5 -d":" <${TEMP}`
XLAND=`cut -f6 -d":" <${TEMP}`
Xrm -f ${TEMP}
X
Xecho "${MODEL}: DESC=${DESC}, NEXT=${NEXT}" >>$LOG
X
Xif [ -z "${NEXT}" ]
Xthen
X	echo "${MODEL}: unable to determine next machine" >>$LOG
X	echo "${MODEL}: aborted" >>$LOG
X	exit 1
Xfi
X
XTITLE=
XOPTIONS=
XCOPIES=
X
Xif [ -n "$3" ]
Xthen
X	TITLE="-t\"$3\""
Xelse
X	user=`grep "^$2:" /etc/passwd | line | cut -d: -f5`
X	if [ -z "$user" ]
X	then
X		user=$2
X	fi
X	TITLE="-t\"${user}\""
Xfi
X
Xif [ -n "$4" ]
Xthen
X	COPIES=-n$4
Xfi
Xparam5=$5
X
Xshift;shift;shift;shift;shift
Xfiles="$*"
X
X# Split out local options from options for remote lp...
X
XLOCALOPT=""
Xfor i in ${param5}
Xdo
X	echo "${MODEL}: option=${i}" >>${LOG}
X	case "${i}" in
X		s|l ) # local options
X			LOCALOPT="${LOCALOPT} ${i}"
X			;;
X		* ) # other options simply passed to remote lp
X			OPTIONS="${OPTIONS} -o${i}"
X			;;
X	esac
Xdone
X
XOPTIONS="${OPTIONS} -oh"
Xif [ -z "${LOCALOPT}" ]
Xthen
X	cat ${files}|uux - -n ${NEXT}!lp ${COPIES} ${OPTIONS} -d${RMODEL}
Xelse
X	LOCALOPT=`echo ${LOCALOPT}`
X	for i in "${LOCALOPT}"
X	do
X		echo "${MODEL}: local option=${i}" >>${LOG}
X		case "${i}" in
X			s ) # small print (portrait)
X				if [ -z "${SMALL}" ]
X				then
X					echo "${MODEL}: no small cmd\c" >>${LOG}
X					echo " found in ${DB}" >>${LOG}
X				else
X#					echo "${MODEL}: small cmd:" >>${LOG}
X#					echo "${SMALL}" | od -cx >>$LOG
X					echo "${SMALL}"
X				fi
X				;;
X			l ) # small print (landscape)
X				if [ -z "${LAND}" ]
X				then
X					echo "${MODEL}: no land cmd\c" >>${LOG}
X					echo " found in ${DB}" >>${LOG}
X				else
X#					echo "${MODEL}: land cmd:" >>${LOG}
X#					echo "${LAND}" | od -cx >>$LOG
X					echo "${LAND}"
X				fi
X				;;
X			* ) # unknown!
X				echo "${MODEL}: unknown local option" >>${LOG}
X				;;
X		esac
X	done|cat - ${files}|uux - -n ${NEXT}!lp ${COPIES} ${OPTIONS} -d${RMODEL}
Xfi
X
Xecho "${MODEL}: COPIES=${COPIES}, OPTIONS=${OPTIONS}, TITLE=${TITLE}" >> ${LOG}
Xecho "${MODEL}: warning - ignoring title" >> ${LOG}
Xecho "${MODEL}: completed on `date` for ${NEXT}" >> ${LOG}
Xexit 0
SHAR_EOF
chmod +x 'remote'
fi # end of overwriting check
echo shar: done with directory "'remotelp'"
cd ..
#	End of shell archive
exit 0