rprint - print on remote sites via UUCP
D'Arcy J.M. Cain
darcy at druid.uucp
Tue Mar 26 00:47:37 AEST 1991
The following is a model file which implements remote printing using UUCP.
This was tested under SV3.2 but should work under systems that use a similar
print spooler system. The idea is to print using standard print semantics.
For example if you have a file that you want to print you might say:
pr file_name | lp -d laser
where laser is a laser printer on a remote system. The file will be
compressed if it is not already so (you must change etc/magic to recognize
compressed files - see comments) and sent with a uux command to the remote
site. Once you install a printer with lpadmin, you can change the name of
the site and the printer at that site by modifying a local file called
remote_mach. Please let me have your comments on this script. If you
make mods to enhance it or allow it to work on other systems please pass
them back so I can try to include them in my copy.
Thanks to Greg Woods (woods at eci386) for the original script and additional
suggestions when reposting this.
---------------------------- start of rprint.sh ---------------------------
#!/bin/sh
#
# rprint.sh - transparent lp interface for a remote printer with compress
#
# Author: Greg A. Woods <woods at eci386>, <woods at robohack>
# Mods: D'Arcy J.M. Cain <darcy at druid.UUCP>
#
PATH=/bin:/usr/bin:/usr/lbin:/usr/local/bin ; export PATH
PRINTER=`basename $0`
ID=$1
USER=$2
TITLE=$3
COPIES=$4
OPTIONS=$5
#
# NOTE, some lp's (notably the one on 3B1's) have 6 options
#
shift; shift; shift; shift; shift
files="$@"
# remote_mach contains a list of printers (as per the lp configuration)
# with the remote machine and the printer name on the remote machine.
# If the last entry is missing then the default printer on the remote
# system is used instead.
#
# Sample remote_mach file:
# | |-----------------------------------------------------------| |
# | o | # List of remote printers | o |
# | | | |
# | o | # printer bill is on system saint at Bill Jones' desk | o |
# | | bill saint lpr5 | |
# | o | | o |
# | | # we also want to print on saint's default printer | |
# | o | saint saint | o |
# | | | |
# | o | # the next one is for the laser on system foo | o |
# | | foo-l foo laser | |
# | o |-----------------------------------------------------------| o |
#
# mktable is in /usr/lbin on most SysV's, and strips comments and blank
# lines while concatenating it's input.
#
MACHINE=`mktable /usr/spool/lp/remote_mach | awk '$1~/^'$PRINTER'$/ {
if (NF == 1) { print "ERROR" }
else { print $2 }
}'`
if [ -z "$MACHINE" ]
then
MACHINE=NOTFOUND
fi
RPRINTER=`mktable /usr/spool/lp/remote_mach | awk '$1~/^'$PRINTER'$/ {
if (NF > 2) { printf "-d%s", $3 }}'`
# Logging - don't bother recording remote printer name
#
# echo "`date +%D-%T`:$PRINTER:$MACHINE:$RAW:-t$TITLE:-o$OPTIONS:-n$COPIES:$files" >> /usr/spool/lp/remlog
# NOTE: uux "sees" single quotes. You must not put them anywhere where
# white space is not allowed (i.e. -t'$TITLE'), as uux will introduce
# a space before the first single quote, and after the ending single
# quote, if there is not already whitespace in these places.
#
# Note also the use of '-C' and '-c' to ensure the data makes the hop!
#
# This version requires "COMMANDS=[...:]lp:uncompress" in the remote
# Permissions file.
# *** NOTE SECURITY ISSUE ***
# One security issue of note is that if you give remote 'lp' execute
# permission, or worse yet remote 'uncompress' or 'zcat' execute
# permission, you can't very easily prevent the remote user from
# exploiting *any* of your printers, except through obscurity (i.e.
# don't let the remote user login and run lpstat or look in
# /usr/spool/lp!). You may be able to hack this to fix this. In
# the environment I was using it this wasn't a problem.
for F in $files ; do
FZ=/tmp/`basename $F`.Z
# D'Arcy J.M. Cain <darcy at druid.UUCP> added the following code to check
# for compressed files and compress them if they weren't already so. The
# file is always compressed before sending.
# The following test requires that file(1) recognize a compressed file.
# I had to add a line to /etc/magic to allow it to do this. The -i
# option to grep is to allow some flexibility if you already have a
# line in /etc/magic and it uses different case. I assume that it will
# have the word compress somewhere in the line at least.
# BTW: the first 2 bytes in a compressed file are 0x1f and 0x9d. How
# you read this depends on the endianness of your processor but the
# following lines works on my 386 with Esix.
# "0 short 0x9d1f Compressed file"
if [ -z "`file $F | grep -i compress`" ]
then
compress < $F > $FZ
else
cp $F $FZ
fi
uux -C "$MACHINE!uncompress < !$FZ | lp -c $RPRINTER '-t$TITLE' '-o$OPTIONS' -n$COPIES"
rm -f $FZ
done
ret=$?
if [ "$ret" -ne 0 ]
then disable -r "uux -n -C \"$MACHINE!lp [...] \" failed." $PRINTER
fi
# I'm not sure if lp will see this, but we've already disabled the printer
#
exit $ret
---------------------------------------------------------------------------
--
D'Arcy J.M. Cain (darcy at druid) |
D'Arcy Cain Consulting | There's no government
Toronto, Ontario, Canada | like no government!
+1 416 424 2871 |
More information about the Alt.sources
mailing list